Set entity (zombie) velocity to a location

Discussion in 'Plugin Development' started by JjPwN1, Sep 21, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    JjPwN1

    What I am trying to accomplish is a type of grenade. When a player throws the grenade, after a delay, nearby zombies will fly towards the grenade.

    I already have accomplished all of this, except I can't figure out how to do the last part; setting zombie's velocities to get launched towards the grenade.

    All I managed to do was to make the zombies get pushed backwards from the direction they were facing:
    Code:java
    1. zombie.setVelocity(zombie.getEyeLocation().getDirection().multiply(-6.0));
     
  2. Offline

    nuclearmissile

    Well yeah, that's what your current code is telling it to do. Fly backwards from the facing direction. To get it to fly towards a certain point, you'll likely have to use some more complicated 3d trigonometry. It's not too hard once you're used to it, here's a thread that explains it thoroughly!

    https://forums.bukkit.org/threads/tutorial-how-to-calculate-vectors.138849/

    Best of luck, and sorry I wasn't able to give specific code examples, I myself don't use vectors terribly often. :3
     
Thread Status:
Not open for further replies.

Share This Page