Chaning velocity - slowing down the minecart

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

  1. Hi guys!

    Could someone help me with the code?

    I'm trying to create a speed switch for minecart. It works perfectly fine when increasing the speed, but I can not get it to slow down. Any ideas?

    Here's the code which I use to increase the speed.

    Code (Text):
          Minecart mine = (Minecart)event.getVehicle();
            Vector cartVelocity = mine.getVelocity();
            mine.setMaxSpeed(25.0D);
            mine.setVelocity(cartVelocity.multiply(1.25D));
     
     
  2. Just set the velocity negative?
     
  3. Like so?

    Code (Text):
    mine.setVelocity(cartVelocity.multiply(-1.50D));
    It will cause the minecart to change direction
     
  4. Hmm how about Maxspeed?
     
  5. please learn math, whenputting something negative, hell yeah it will change direction. try 0.250 for example. this will slow the minecard down.
     
    • Agree Agree x 2
    • Optimistic Optimistic x 1
  6. Multiply it by a number less than 1...
     
  7. Slowing it down by adding 0.250 to the current velocity.... You're such a math genius.

    To TS, try instead of multiplying, subtract. Or use like setVelocity(getCurrentVelocity - 1.25);
     
    • Funny Funny x 2
  8. What? It's physics, a negative velocity means a deceleration. Velocity doesn't care about direction. Velocity is the speed in a given direction.
     
  9. Does it work for you ?
     
  10. In pratice it will change the direction. I tried it...
     
  11. minecart.setVelocity(minecart.getVel() * 0.9) ; (anynumber less than 1. )