Addforce without building up infinitely

I’m trying to look for a way to push a vehcile forward and have it go at a certain speed. When I use ‘AddForce’ the vehicle keeps going faster and faster endlessly.

What is the best way to do this?

Just reduce the force based on the current speed. Check the current speed against a max speed variable and if current speed = max speed then stop adding force.

You have to approach these issue with your logic hat on. “Why is my speed infinite? Oh, because I’m just adding more force all the time. How do I stop that? Reduce the force being added.” etc etc.

Really digging how Blazing Sails looks! We always need more pirate games :slight_smile:

There are many way how you can do it, one is as wickerman123 suggested to regulate amount of force by speed.

Another is to add “air friction” where the faster your vehicle goes the more drag force it will experience. Which is as simple as doing this:
Fdrag = 0.5 * V^2 * Dscale
where V is velocity vector and Dscale is an arbitrary float that you tweak yourself to get behavior that you like.
If you want to go with “realistic” approach then Dscale becomes:
Dscale = q * A * Cd
where q - fluid density, A is area of vehicle cross section and Cd is a drag coefficient (can consult wikipedia on some example values like these https://upload.wikimedia.org/wikipedia/commons/thumb/3/37/14ilf1l.svg/220px-14ilf1l.svg.png)

Fdrag force goes the opposite of velocity vector and you can add with with AddForce. The main benefit of having drag as separate force is so that your vehicle has a speed limit regardless of how other forces act on it. Meaning if it falls from a cliff it will reach some terminal velocity instead of accelerating indefinitely or hitting a MaxSpeed project setting.

2 Likes

Yeah, totally makes sense. Haha I wasn’t thinking very clearly. But thanks for the help I got it figured out now. :slight_smile: