- Home /
Question by
ChickenPoint · Mar 28, 2021 at 12:55 PM ·
velocitydrag-and-dropobject movement
How can I calculate the velocity of an object that moves with drag and drop controls ?
I want to calculate the velocity of an object. That object can move by drag and drop. But I need the last velocity of that object just before you release it. How can I get that velocity? It's 3d.
Comment
Does the object use a rigidbody? If so, you can just get the velocity of the rb OnRelease, through rb.velocity
.
If not (assu$$anonymous$$g it's just manually setting the transform), you can save the last position, and subtract it from the current one, every frame, to calculate the velocity (or change in position over time). For example:
Vector3 lastPos;
void Update()
{
// Dragging logic here
Vector3 velocity = transform.position - lastPos;
Debug.Log(velocity);
lastPos = transform.position;
}
it has a rigidbody. How I use rb.velocity without giving it an XYZ value, just for read the velocity?