setMotion and setRotation

Discussion in 'Development' started by DaRealPandaz, Aug 12, 2019 at 8:33 PM.

  1. DaRealPandaz

    DaRealPandaz Silverfish

    Messages:
    15
    GitHub:
    mrpandaz
    Hello, I have been trying to make my boss move smoothly for the last 10 hours and i've finally decided to ask for some help. I am trying to get my boss to sprint/walk to a viewer in 5 blocks range, attack the player, and also look at the player.(I have the range down and the attack). I've heard that i need to use Sin/Cos/Tan but i dont know how to apply that to my php coding.

    PHP:

    foreach($this->entity->getViewers() as $viewer) {
        if (
    $viewer instanceof Player) {
            if (
    $viewer->distance($this->entity->getPosition()) < 5) {
                
    $attackdamage mt_rand(120);
                
    $ev = new EntityDamageByEntityEvent($this->entity$viewerEntityDamageEvent::CAUSE_ENTITY_ATTACK$attackdamage);
                
    $viewer->attack($ev);

            }
        }
    }

    Thank you for your time.
     
  2. Deniel

    Deniel Spider Jockey

    Messages:
    30
    GitHub:
    DenielWorld
    Doesn't seem like that code will move the entity. Also, try focusing more on what you can do, and ask for help on new things.
     
  3. DaRealPandaz

    DaRealPandaz Silverfish

    Messages:
    15
    GitHub:
    mrpandaz
    I'm saying I need help with moving the entity. I don't really know where to start.
     
  4. Deniel

    Deniel Spider Jockey

    Messages:
    30
    GitHub:
    DenielWorld
    I recommend taking a look at how the AI driven mobs from PEX or VanillaEntityAI function. Can give you a hint probs.
     
  5. DaRealPandaz

    DaRealPandaz Silverfish

    Messages:
    15
    GitHub:
    mrpandaz
    I have and I understand like 1% of what they are doing. Ill try again i guess
     
  6. wolfdale

    wolfdale Zombie

    Messages:
    343
  7. DaRealPandaz

    DaRealPandaz Silverfish

    Messages:
    15
    GitHub:
    mrpandaz
    ok i was reading it and this part started to mess with my brain.

    PHP:

    if($x ** $z ** 0.7){
    $this->motion->0;
    $this->motion->0;
    } else{

    Can someone explain?
     
  8. wolfdale

    wolfdale Zombie

    Messages:
    343
    It prevents the entity from having motion that is too small
     
  9. DaRealPandaz

    DaRealPandaz Silverfish

    Messages:
    15
    GitHub:
    mrpandaz
    I understand slightly more now. I decided to open Notepad and start writing down what everything is doing. This is what I have so far

    Code:
    Players X = 30
    Players Y = 38
    Players Z = 82
    
    Boss X = 25
    Boss Y = 40
    Boss Z = 80
    
    PX Away From BX = PX - BX (30-25)[5] ($x)
    PY Away From BY = PY - BY (38-40)[-2] ($y)
    PZ Away From BZ = PZ - BZ (82-80)[2] ($z)
    
    if $x * $x + $z * $z less than 0.7 then dont move
    
    else the amount of blocks away is absoulte value of $x + $y ($diff)
    
    $diff = 7
    
    
    move the boss's x at 1 * 0.15 * ($x / $diff) [Motion: 0.10] {Player Is Too Close But Not Close Enough For Boss Not To Move}
    
    
    Am I Basicallly Correct So Far?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.