# How can I find the velocity on a rigidbody which moves using Lerp?

Hello,

I need some help with finding the velocity on an object which moves using a Vector.Lerp. It seems that if you move an object the way stated, a velocity on the rigidbody is not applied.

This seems strange to me as the lerp uses a time in which it moves the object between two points.

Is there something simple that i have missed, or is there a way to find the velocity of an object which moves using lerp?

Here is some sample code, never mind some of the bad scripting since it’s only a test!

``````using UnityEngine;
using System.Collections;

public class MyPlayerController : MonoBehaviour
{
public Transform myTransform;
public Vector2 currentLocation;
public Vector2 newLocation;

public float newLocationY;
public float smooth;

public float nextMove = 0.1f;
public float moveRate = 0.1f;

public float tilt;

void Start()
{
myTransform = transform;
}

void Update()
{
currentLocation = transform.position;

if(Input.GetKeyDown(KeyCode.LeftArrow) && Time.time > nextMove && myTransform.position.y < 8f)
{
nextMove = Time.time + moveRate;
newLocationY = currentLocation.y + 3f;
newLocation = new Vector2(0, newLocationY);
}
else if(Input.GetKeyDown(KeyCode.RightArrow) && Time.time > nextMove && myTransform.position.y > -8f)
{
nextMove = Time.time + moveRate;
newLocationY = currentLocation.y -3f;
newLocation = new Vector2(0, newLocationY);
}
//Move
myTransform.position = Vector2.Lerp(currentLocation, newLocation, smooth * Time.deltaTime);
//Rotate

//!
//!This is always nort!
myTransform.rotation = Quaternion.Euler(0, 0, rigidbody2D.velocity.y * -tilt);

//This ALWAYS displays (0.0, 0.0)
Debug.Log(rigidbody2D.velocity);
}
}
``````

Velocity only applies to the built-in physics system to let the ball fall, bounce and roll on it’s own. It sort of means “how much is the automatic movement?”

So, if you’re moving it yourself, with Lerp or however, velocity should be zero. If it wasn’t zero, the ball would always move a little extra “randomly” from where you put it.

Imagine you’re letting physics drop a ball (using a rigidbody.) It gains speed, falls, and the Y velocity auto-increases. When it hits and bounces, Y-velocity flips and is reduced (based on how bouncy it is.) OK, now imagine your code 1-time teleports the ball sideways by x=2 in a single frame. That doesn’t change velocity at all. The ball keeps falling at the same speed, from the new position, like a RoadRunner cartoon. Or the old dungeon teleporter trap at the bottom of a pit.

You can compute velocity yourself: new position minus old position. In line 41. currentLocation is now where you used to be, so: `Vector3 vel = transform.position - currentLocation;`. You might think “but that’s just how much I moved!” But that’s the definition of velocity.