- Home /
How to find the velocity of a gameobject that has be hit by the spherecast ?
I'm trying to figure out the velocity of a game object that has been hit by a sphere cast im casting from the camera. For now i figured out how to calculate the distance. Can some one please guide me on how to calculate the velocity
Thanks in advance!
Answer by ImpOfThePerverse · Apr 19, 2018 at 06:40 PM
If the object has a non-kinematic rigidbody attached (meaning its velocity is being determined by physics) you can get the velocity by using GetComponent to get the rigidbody, and then rigidbody.velocity to get the velocity.
If the object is not being moved by physics, I'm pretty sure you'd need to attach a script to any object that you want to get the velocity of, that keeps track of its velocity (or its position during the last frame) in a public variable. Use GetComponent to get the script, and either read the calculated velocity, or calculate the velocity from the last position (velocity = transform.position - lastPosition).
Your answer
Follow this Question
Related Questions
Velocity powered rigidbody on a moving platform without parenting. 3 Answers
How can the resultant velocity of an object after a potential collision be predicted? 1 Answer
Get all surrounding gameObjects 1 Answer
Using CheckSphere to affect another Game Object? 2 Answers
Enemy Sighting Using SphereCast 0 Answers