Help with velocity

Discussion in 'Spigot Plugin Development' started by Voigon, Jul 13, 2018.

  1. Hello,
    I am trying to create an animation like the one here but for some reason when going up the elevator isn't smooth at all. This is the current code responsible for the mechanic (There is currently only going up, didn't get to going down as for now).

    Can anyone explain to me what is wrong in my code?
    I've tried to play with the Y of the vector of falling block but it is 0.
  2. joehot200


    You should be setting the velocity of the player as opposed to teleporting the player. Teleportations can never be smooth like in the animation.
    • Informative Informative x 1
  3. Follow @joehot200 's suggestion or alternatively for a smooth effect, you want to increase the Y by a very small number (0.1) every tick, rather than 1.

    My personal favourite for elevators is using the levitation effect. It has the smoothest feeling for the client, they can still move freely and it can be used both for going up and going down. For upwards movement, use an amplifier between 1 and 5, for downwards movement use an amplifier between 250 and 254.
    • Like Like x 2
    • Informative Informative x 1
  4. Thanks guys!
  5. What should the velocity be?

    Need it for 1.8 :\
  6. Honestly, just mess around until you find a good value for your needs. It'll depend on how fast you want your elevator to be and such.

    Make sure they are in vectors though :p
    • Agree Agree x 1
  7. I've tried to, it is either not smooth or I can't see the falling block. Can you give me a range that I should try?
    By the way, should I set X and Z too in the velocity?
  8. You need to constantly set the velocity to something, I don't think it'll work by only setting it once. Put it on a timer
  9. Already did, it is running every tick. What about the velocity itself? can you give me a direction? positive? negative? smaller than 1? 100-200? 10-20?
  10. For Y, try something like -0.3, it'll be slow. You can change it depending on how fast you want it.

    Also, it's not smooth? What do you mean?

    Code (Java):
    Vector vector = new Vector(0, -0.3, 0);
  11. Won't negative number make it go down?
  12. Yes, that is for a down function, for up, make it positive
  13. It is a lot better now, thank you.
    I've still ran into a problem, the player is higher than the block. Both are moving via velocity only.
    This is my current code: