1.13.2 Smoothly Moving Amorstand

Discussion in 'Spigot Plugin Development' started by Manicraft1001, Jan 24, 2020.


Whats the best way to move an armorstand like this?

  1. Setting its velocity

  2. Teleporting it

    0 vote(s)
  3. Something other

Thread Status:
Not open for further replies.
  1. Hello guys,

    my goal is to create a create a armorstand, wich summons at the player,
    smoothly move in the looking direction of the player +4 blocks and finally returns to the player.
    I alredy tried it with p#setVelocity, but it isn't that reliable and doesn't work in air.
    I made a little example, how the armorstand should move: jsfiddle (Just click the red element to start the animation).

    Thanks for any help
  2. Try a runnable that moves it by movinf it's location in small vectors (for animations I usually do 1 tick runnables so it's smooth but you can tweak that to be longer if it's too fast)
    • Agree Agree x 1
  3. Thank you for your answer.
    As i wrote, setting the velocity is not that easy.
    It shoud work in the air, so if we do it with velocity we need to prevent the armorstand from falling at y cords.

    Is that, what you meant?
  4. If you want to make it move through the air, I believe disabling gravity after (or before I forget which) each velocity change should do the trick
  5. Ok, never tried to disable and enable it.
    But then, only 1 question is remaning. I need to calculate the path of it to calculate each velocity.
    How should i do that?
  6. Path's just a straight line. You'll need to set the yaw of the stand as well to make that rotation effect you described.
    • Optimistic Optimistic x 1
  7. The rotation effect shouldn't be a problem, just rotating it every tick by a few deg.
    Currently, the most important question is, how to slowly increse the velocity, move a bit and then decrease again?
  8. Well, this really isn't that hard. As you are iteratively adapting your velocity/position each tick, you can also adapt the initial/ending velocity (and position).
    Suppose you have a piecewise-defined function f. For simplicity, let's say that function is one-dimensional. You could define the function for the velocity as follows:
    v(t) = ax^2 + bx + c for 0 <= t < t0,
    v(t) = v0 for t0 <= t < t1,
    v(t) = dx^2 + ex + f for t1 < t < t2.
    You'd have to calculate the values of the unknowns a, b, c, d, e, and f, for example like this:
    Using the constraints v(0) = 0; v(t0) = v0; v'(t0) = 0, we can get:
    v(0) = 0 = 0*a + 0*b + c
    v(t0) = v0 = t0^2*a + t0*b + c
    v'(t0) = 0 = 2*t0*a + b
    We can see instantly, that c has to be 0 which leads us to a simple linear equation sytsem with 2 equations and 2 unknowns:

    v0 = t0^2*a + t0*b
    0 = 2*t0*a + b

    We can see, that b has to be -2*t0*a. Inserting that into the first equation yields:
    a = -v0 / t0^2
    b = 2 v0 / t0

    Now do the same for d, e, and f (the result will be the same except for a time-shift and reflexion at the y-axis) and you should be good to go. If you want to compute for every time-step t the path; you'll have to integrate the formula.
    Simply plug the values for t0, t1, t2 and v0 into your formula (v0 is the maximum velocity, from 0-t0 you are accelerating; t0-t1 is the time span of holding the constant velocity and t1-t2 is the time t), vectorize that thing and you're good to go!
  9. TeamBergerhealer


    I use packets to have full complete domination of the relative position updates of the armorstand, and no interference from the server (block/entity collision, other plugins, etc.). The biggest problem using the Bukkit API is that the synchronization of your position changes doesnt occur every tick, but every 2 or 4 ticks, with a minimum threshold of difference before a packet is sent to the client with the update. Only way around this, is packets.
  10. I think the question here is on how to enable a "fade-in, fade-out" animation (which I have lined out, even tho in hindsight an exponential S-curve would have probably been better than a quadratic term). But I didn't know that Bukkit only updates every 2-4 ticks. Do you mind telling me what package one has to send (probably something like EntityRelMove, right?)
  11. TeamBergerhealer


    @Schottky I was mostly commenting on the poll the OP opened ('something other')

    Yep, the relmove packets are used for that. There are several variants of it (with yaw/pitch and position, position only, yaw/pitch only). There is also a teleport packet, but Ive noticed that it behaves differently on clients than the rel move. Because the relative updates can drift over time, the server sends an absolute position update every so often to keep things in sync.

    I believe the relative position updates use dx/dy/dz multiplied by 32. It differs per minecraft version.
    • Friendly Friendly x 1
Thread Status:
Not open for further replies.