changing Motion of arrow

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

  1. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    268
    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:
    213
    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:
    268
    GitHub:
    cupidonsauce173
    I will try right now
     
  4. CupidonSauce173

    CupidonSauce173 Zombie

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

    Muqsit Chicken Verified

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

    KielKing Zombie

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

    wolfdale Zombie

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

    CupidonSauce173 Zombie

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

    CupidonSauce173 Zombie

    Messages:
    268
    GitHub:
    cupidonsauce173
    yes
    does nothing


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

    KielKing Zombie

    Messages:
    213
    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:
    268
    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:
    268
    GitHub:
    cupidonsauce173
    Nvm, yes I see the hey
     
  13. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    268
    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

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

    KielKing Zombie

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

    wolfdale Zombie

    Messages:
    258
    Thats the same as what i just said isnt it
     
  17. KielKing

    KielKing Zombie

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

    CupidonSauce173 Zombie

    Messages:
    268
    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:
    124
    Try my code
     
  20. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    268
    GitHub:
    cupidonsauce173
    Oof thank you
     

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.