Moving Armorstand From One Location to Another

Discussion in 'Spigot Plugin Development' started by Max604, Jul 12, 2018.

  1. Hello,

    How would you go about moving an armorstand from one location to another? Do I need to calculate the vector between the two points and divide it into smaller vectors accordingly and then teleporting the armor stand a little bit each time until it reaches the end of the path? Or something else. I'm intending to do this in the sky so i wouldn't have gravity.

  2. It depends what effect you want to achieve, if you want to do it as a smooth animation teleport it in small vectors, if you want it to go from one place to the other regardless of appearance just .teleport(Loc)
  3. MiniDigger


    can also just set the velocity instead of teleportation.
  4. Yes, I'm trying to achieve an animation-like smooth movement.
  5. I was reading some previous articles and I think some of them had issues with velocity movement when nogravity is enabled.
  6. I'm pretty sure entity ignores velocity if it has noGravity..
    You could make a repeating task that would teleport the armorstand to location every tick and would add x y z to location until it would reach destination.
    It should look smooth enough..
  7. I'm thinking of this loigc: create the vector between the two locations, normalise it, divide that by whatever (which will determine its observable speed) and then in a repeating task keep adding this vector to the current location until it reaches the end location. Sound decent?
  8. yes but don't normalize it, i will say example like so:
    If i want a repeating task that would count from number 10 to number 20 in 20 ticks you need to

    difference = end - start
    increasePerStep = difference / numberOfRuns(ticks)
    current = start
    runTaskTimer {
    if(current >= end) cancel()
    else current += increasePerStep

    EDIT: count the number of runs and cancel it based on that instead of comparing x, y, z because there will be very small inaccuracy so it wont be equal..
    #8 Mareckoo01, Jul 12, 2018
    Last edited: Jul 12, 2018
  9. Looks nice, would that increasePerStep be a single vector that is added to the current?
  10. yes..
    int steps = 20
    Location current = startLocation.clone()
    Vector adding = endLocation.toVector()
    // divide x y z with steps
    adding.divide(new Vector(steps, steps, steps))
    int ran = 0
    runTaskTimer {
    // not 100% sure if this method exists, add to x y z if it doesn't exist
    //do stuff
    if(++ran >= steps) cancel()
    i'm not on my pc so i can't check it...
  11. I would do this:
    Code (Java):
  12. As mentioned above, this is ignored when nogravity is selected.