# Calculate speed vehicle physics 2d racegame

I am currently working on a 2d racegame where I am using physics to move a vehicle. On my form I would like to add a label containing the speed on the vehicle.

My physics knowledge is a little rusty, haven't done anything with it for a while, so I am asking the following question. Which of the calculations in my code represent the total velocity of my vehicle?

My relevant code:

    //our simulation object
class RigidBody
{
//linear properties
private Vector m_position = new Vector();
private Vector m_velocity = new Vector();
private Vector m_forces = new Vector();
private float m_mass;

//angular properties
private float m_angle;
private float m_angularVelocity;
private float m_torque;
private float m_inertia;

public void Update(float timeStep)
{
//integrate physics
//linear
Vector acceleration = m_forces / m_mass;
m_velocity += acceleration * timeStep;
m_position += m_velocity * timeStep;
m_forces = new Vector(0,0); //clear forces

//angular
float angAcc = m_torque / m_inertia;
m_angularVelocity += angAcc * timeStep;
m_angle += m_angularVelocity * timeStep;
m_torque = 0; //clear torque
}
}


Hopefully someone will be able to help.

• the code you posted is very long and I doubt someone will read it completely to answer. Could you please remove those parts which are not relevant for the physics? such as graphics, getters and setters perhaps and so on. – Turms May 3 '17 at 6:39
• Hello; I have rolled back the question to it's previous version as it was asking a second question in the same question post, and it was not related to the first question that you asked, and to the answer that someone posted. If you have a second question, please create a second question post. – Vaillancourt May 3 '17 at 19:21

float speed = m_velocity.Length();

float kmh = speed * 18f / 5f;