# High rigidbody drag value gives weird speed readings

when calculating speed in unity

    public float speed = 0;

Vector3 lastPosition = Vector3.zero;

void FixedUpdate()
{
speed = (transform.position - lastPosition).magnitude;
lastPosition = transform.position;
}
It all goes well... However when increasing the drag value of the objects rigidbody component to 100 this speed value goes haywire! I have made a physics based movement system using the addforce rigidbody function to move along whichever local axis and used drag as a replacement for ground friction when walking along a surface becuase physics materials didnt work

How can I get a proper speed reading?

• Rigidbody(2d) has velocity property. Jan 6 at 10:44
• How would i write that? I am in a unity 3d scene... i did: float speedInUnitPerSecond = GetComponent<Rigidbody2D>().velocity.magnitude; but im using a 3d rb not 2d... and im not sure how to calculate last position using vector 2... Jan 6 at 23:55
• Just use the 3d one - float speedInUnitPerSecond = GetComponent<Rigidbody>().velocity.magnitude; Jan 7 at 6:50