- Home /
Rigidbody velocity and velocity.magnitude always return 0
I'm trying to run some math on my projectiles to find intersect points so I can have some target prediction. The issue is that the rigidbody.velocity and rigidbody.velocity.magnitude always return zero.
I move the objects with addforce, I don't move them by their transform.position. Why is their velocity zero, and how do I go about fixing it?
Example moving projectiles: http://i.imgur.com/PE9JFAH.webm
Code to move projectile:
private void ApplyForce(Transform targetTransform)
{
Vector3 angle = (targetTransform.position - transformV.position).normalized;
GetComponent<Rigidbody>().AddForce(angle * (speed * 10));
}
That game's lookin' good, friend.
If you are successfully moving a rigidbody with AddForce() and company, there's no reason reading the velocity ought to be zero. Are you checking the velocity in the same frame you call AddForce? That might be improper and thus the cause, I'm not actually sure.
Thanks! The rigidbody is successfully moved with AddForce, in the correct direction as well. I check the velocity after the above method returns. Edit: Seems the velocity is not set till the next fixedupdate. Which is why I'm seeing it as being set to 0.
Answer by AlwaysSunny · Mar 31, 2015 at 05:33 PM
So evidently checking velocity before the end of the frame won't show that frame's changes. That's useful to know. Since you're setting the initial impulse force, you could find the resultant velocity mathematically using one of the big four kinematic equations. :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613191805im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Rigidbody character controller can't walk on stairs 0 Answers
Velocity powered rigidbody on a moving platform without parenting. 3 Answers
Character Joints and Animations results in strange physic animation 1 Answer
Gravitational Object Creation for 3D Game 1 Answer
2d side scrolling problem 5 Answers