actual car speed kilometer

Hi guys
I’m using Vector3.Lerp to move one object I want this object to move as actual speed like if the speed is 100 kilometer per Hour
that mean 27.78 meter per second ,in unity mean 27.78 unit per second.
I use this cod
journeyLength = Vector3.Distance(car.transform.position, new Vector3(_xCurrent, _yCurrent, _zCurrent));

float distCovered = (Time.time - startTime) * _MoveSpeed;
float fracJourney = distCovered / journeyLength;
if (journeyLength >0)
car.transform.position = Vector3.Lerp(craneHolderForAllParts.transform.position, new Vector3(_xCurrent, _yCurrent, _zCurrent), fracJourney);

the code working but the speed not actual speed.

any Help Please.

float KPHinMPS = 1024.0f / 3600.0f; // how many meters you move per second at 1KPH.
float KPH = 80.0f; // how many Kilometers per hour to move
float ThisFramesMovement = Time.deltaTime * KPH * KPHinMPS; // How much to move this frame.

I don’t recommend setting the position directly. Instead, use a rigidbody and apply force.

Hi Jaimi
please correct me if I’m wrong
if I want to move the car 100 Kilometers per hour should I use this code

float KPHinMPS = 1024.0f / 3600.0f; // how many meters you move per second at 1KPH.
float KPH = 80.0f; // how many Kilometers per hour to move
MoveSpeed=Time.deltaTime 100 KPHinMPS
float distCovered = (Time.time - startTime) * _;MoveSpeed

is this correct
and regarding rigidbody you recommend to add force to car rigidbody , why

Thanks you

No, that is incorrect. In my example above ThisFramesMovement is keeping track of how much you are moving that frame (Time.deltaTime is tracking how much time has passed since the last frame).

You should use some sort of physics component (like a RigidBody, or a charactercontroller perhaps), so that your car will interact with the world (ie, go up and down hills, hit things, etc). Just changing the transform position will ignore everything.

For example, if you were using a character controller on your car, you would call the “Move” function, calculating the movement vector * ThisFramesMovement.

If you were using a RigidBody, you would use “AddForce” to add force to the object, and then monitor the “velocity” vector length to check the speed.

Hi Jaimi
Thank you for this information,I’m not sure how can I do it but I will try . thank you again