Creating a path automatically

Discussion in 'Spigot Plugin Development' started by Z3tr0nix, May 29, 2017.

Thread Status:
Not open for further replies.
  1. What I want to do: I set loc1 and loc2 and the entity moves from loc1 to loc2 gradually (not teleport, but more like walk/fly)



    on a side note, how would I set the hands of an armorstand to move gradually also? like one armorstand is there and another armorstand is there in different poses, how would I set it so that the 1st armorstand when going to the second armorstand it looks like its limbs are moving to match the second armorstand, gradually?
     
  2. ScarabCoder

    ScarabCoder Retired Resource Staff
    Retired

    The first part is a bit tricky, since it involves NMS and setting an entity's pathfinding location. Here's what I found in a Google search: https://bukkit.org/threads/entity-pathfinding-and-targetting.103322/
    Since ArmorStands don't have an AI, you may need to get an other entity to which the armorstand is constantly being teleported to.

    For moving the armor stand's legs/arms, you'll need to do that in a timer. Just increase the rotation incrementally, then reverse it after it gets to a certain point.

    EDIT: Looking closer at the link I put above, it actually doesn't require NMS. It does teleport the entity, but very gradually (not noticeable as teleporting).
     
  3. yes I had thought of that, but how do I create the path??? like it gets every decimal (.1, .2) in the middle of the 2 cords
     
  4. Define what you mean by "it gets every decimal". You have to be very specific about everything you mean when you're asking for development help.
     
  5. ScarabCoder

    ScarabCoder Retired Resource Staff
    Retired

    Use a Bukkit Scheduler timer to increase it every x ticks.
    If you don't know what those are, you should probably try something easier.
     
  6. m8 i know how to move it, but i need help defining in what direction to move it in...
     
  7. If you have two locations

    l1: Start location
    l2: End location

    Create a vector: vector = l2 - l1

    This vector gives you the direction to move your entity. You now have to decide on a speed, for example 2 blocks per second. That would be 1/10 blocks per tick. For one teleport every tick that leaves you with length(vector)*10 teleports. Now simply teleport your entity every tick by normalized(vector)/10
     
  8. Sorry, I am new to minecraft vectors, can you show me some code?
     
  9. Code (Java):
    Vector vector = new Vector(l2.getX() - l1.getX(), l2.getY() - l1.getY(), l2.getZ() - l1.getZ());
    Vector java docs
     
    • Informative Informative x 1
  10. from what I understand vector is basically location, how would it help me?
     
  11. A vector has two qualities, a magnitude and a direction. In order to get your object to move from one location to another, you will need a vector.
    For example: If you wanted the player to move 3 blocks north, the magnitude is 3, and the direction is north. This is a simple vector.
     
  12. As pvprealm said, vector is not a location (partially, depend how defiend) ,
    to get your vector from point A to point B, you would do VecB- VecA which will give you
    and thats what Nikl code showed, he took each axis from each distance and done it, alternative way to do it would be locTo.toVec() - locFrom.toVec()
     
Thread Status:
Not open for further replies.