1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

changing Motion of arrow

Discussion in 'Development' started by CupidonSauce173, Feb 9, 2019.

  1. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    Hello, I try to change the motion of the arrow to be faster but I have no clue on how to do it. Someone have an idea ?
     
  2. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    PHP:
    public function onEntityShootBow(EntityShootBowEvent $ev): void{
        
    $projectile $ev->getProjectile();
        if(
    $projectile instanceof Arrow){ //pocketmine\projectile\Arrow
            
    $motion $projectile->getMotion();
            
    $motion->multiply(3);
            
    $projectile->setMotion($motion);
        }
    }
     
    Muqsit likes this.
  3. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    I will try right now
     
  4. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    it doesn't do anything
     
  5. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Try
    PHP:
    $projectile->setMotion($projectile->multiply(3));
     
  6. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    did you include
    PHP:
    use pocketmine\entity\projectile\Arrow;
     
  7. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    PHP:
    public function onEntityShootBow(EntityShootBowEvent $event){
        
    $event->setForce($event->getForce() * 5);//change 5 to any multiplier you want
    }
     
  8. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    tried, change nothing
     
  9. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    yes
    does nothing


    it sound like if the server doesn't apply the changes
     
  10. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    have you registered your class as an event listener?

    if yes, add var_dump("hey"); before the defining of $projectile and tell me if it outputs "hey"
     
  11. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    doesn't appear, weird and yes, the class is registered as an event Listener and its the Main
     
  12. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    Nvm, yes I see the hey
     
  13. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    ok it works but the arrows always go in one direction (even if you shoot at the opposite direction)
     
  14. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Because i think he meant $projectile->getMotion()->multiply(3) instead of $projectile->multiply(3)
     
  15. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    use my method
     
  16. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Thats the same as what i just said isnt it
     
  17. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    not really, you didn't tell him to set the motion, only get and modify it
     
  18. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    no it works, but you need to put stuff like 0.3 motion because 2-3 make the arrow to bug.
     
  19. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    Try my code
     
  20. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    Oof thank you
     
  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.