# how to solve for a float when you have vectors?

A have this:

``````Vector3 vector_totalSpeed = normalized_projection * totalSpeed;
float accel = 9.81f * (Mathf.Sin(slopeAngle * Mathf.Deg2Rad) - Mathf.Cos(slopeAngle * Mathf.Deg2Rad) * frictionCoefficient); //metros sobre segundo al cuadrado //cos y sin del ángulo siempre son positivos, por lo tanto, solo puede dar negativo si la fricción es > al peso
Vector3 acceleration = normalized_projection * accel;

Vector3 extraDisplacement = vector_totalSpeed * deltaTime + acceleration * deltaTime * deltaTime / 2;
``````

Am basically solving for the displacement with constant acceleration. Then, later in the code, am trying to solve for the `totalSpeed` float with the known movement vector, like this:

``````float accel = 9.81f * (Mathf.Sin(slopeAngle * Mathf.Deg2Rad) - Mathf.Cos(slopeAngle * Mathf.Deg2Rad) * frictionCoefficient);
Vector3 acceleration = normalized_projection * accel;

//movement = vector_totalSpeed * deltaTime + acceleration * deltaTime * deltaTime / 2;
Vector3 vector_totalSpeed = (movement - (acceleration * deltaTime * deltaTime / 2)) / deltaTime;
//Vector3 vector_totalSpeed = normalized_projection * totalSpeed;
totalSpeed = vector_totalSpeed.magnitude;
``````

As you can see, it works, but am calculating a square root to get the magnitude. Is there another way of doing this? I can think of a way that works, but it´s only for 2D, and this is 3D.

RE-EDIT:

The using Vector3.Dot() I had before was wrong, sorry. As a Dot product returns at a value of 1(normalized). Which is actually useful in many situations, just not determining speed, lol. Here is the correct answer

``````/// If using rigidbody
float speed = rigidbody.velocity.magnitude;

/// If using no rigidbody
float speed = (transform.position - mLastPosition).magnitude / elapsedTime;
mLastPosition = transform.position;

/// If using CharacterController
Vector3 horizontalVelocity = controller.velocity;
horizontalVelocity = new Vector3(controller.velocity.x, 0, controller.velocity.z);

float horizontalSpeed = horizontalVelocity.magnitude;
float verticalSpeed  = controller.velocity.y;
float overallSpeed = controller.velocity.magnitude;
``````

float speed = rigidbody.velocity.magnitude;