I am using Unreal Engine 4.20.3 and need help making a vehicle drive at a specified speed.

If I have a vehicle driving at 100km/h, and in 200m time it needs to be driving at 80km/h, how would I calculate how much the brake needs to be applied?

I can calculate how much force the brakes need to apply to the vehicle with the following:

float CurrentKineticEnergy = (VehicleMovement->Mass * 0.5) * FMath::Square(CurrentVelocity);
float TargetKineticEnergy = (VehicleMovement->Mass * 0.5) * FMath::Square(TargetVelocity);
float Work = (CurrentKineticEnergy - TargetKineticEnergy) / NumberOfWheels;
float Force = Work / Distance;

I can also work out the force of the brakes when they are fully applied:

BrakeForce = MaxTorque / WheelRadius;

I am struggling to tie this together however. Reading the code I have been unable to find anything on braking/stopping distances or friction coefficients.

If anyone could point in me the right direction I would be grateful!

I’m not sure this can be reasoned with any accuracy. In-between the brake and the rigid body are four tires with non-linear responses to slip angle. The problem, then, is that the braking torque doesn’t convert linearly into a force on the rigid body. It gets much more complex if you want the vehicle to turn while it is slowing.

Your problem is more even complex because you require a non-linear deceleration. I’ll try to explain that. If you assume linear acceleration then we can write down an equation for the distance travelled as a function of time

DX = V0DT + 0.5aDTDT

where DX is the distance travelled, DT is the time taken, V0 is the initial speed, and a is the linear deceleration. The problem here is that you don’t know the acceleration or the time taken so you can’t solve the equation. To compute the linear acceleration you need to know how much time it took to reach 800m but to work out how much time it took you need the deceleration. This is a chicken and egg problem.

There are many acceleration profiles that will solve your problem but you need to have extra information about their desired properties in order to choose one from the vast family of solutions. This sounds like for a problem suited to the technique of Lagrange Multipliers [ https://en.wikipedia.org/wiki/Lagrange_multiplier ]