Entity Velocities, Somewhat Advanced

Discussion in 'Plugin Development' started by Freelix2000, Aug 2, 2014.

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

    Freelix2000

    I am trying to make a plugin in which one entity's velocity is set so that it will be launched towards another entity, and while I have done some sort of complicated things with velocities, I don't have a great understanding of what exactly a vector is or how to calculate such a velocity. If you know how to do this, please comment.
     
  2. Offline

    AoH_Ruthless

    Freelix2000
    The vector between Entity A and Entity B is A.getLocation().subtract(B.getLocation()).toVector(). Let's call the vector 'link'.
    Now that we have the linking vector. A.setVelocity(link.add(new Vector(0, 3, 0)).normalize() will launch the entity with a bit of lift and normalize it.

    Note that this might not work exactly how you want it and I haven't worked with this stuff in a little bit so tweak it to your will.

    Explanation above in code:
    Code:java
    1. // Don't keep it null ...
    2. Entity a = null;
    3. Entity b = null;
    4. Vector link = a.getLocation().subtract(b.getLocation()).toVector();
    5. a.setVelocity(link.add(new Vector(0, 3, 0)).normalize());
     
  3. Offline

    Freelix2000

    Okay, I'll play with that. Thanks!
     
Thread Status:
Not open for further replies.

Share This Page