# Chaning velocity - slowing down the minecart

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

1. ### Invaerne

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. ### TheBlackTeddy

Just set the velocity negative?

3. ### Invaerne

Like so?

Code (Text):
mine.setVelocity(cartVelocity.multiply(-1.50D));
It will cause the minecart to change direction

5. ### NormaalBart

please learn math, whenputting something negative, hell yeah it will change direction. try 0.250 for example. this will slow the minecard down.

• Agree x 2
• Optimistic x 1
6. ### Warren1001

Multiply it by a number less than 1...

7. ### TheBlackTeddy

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 x 2

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. ### Bungeefan

Does it work for you ?

10. ### Invaerne

In pratice it will change the direction. I tried it...

11. ### iSoda

minecart.setVelocity(minecart.getVel() * 0.9) ; (anynumber less than 1. )