- Home /
A sphere moved by relativeforce is acting wierd?
Hi, I have this sphere that I am moving by this script
var fwdspeed : float = 10;
function FixedUpdate () {
rigidbody.AddRelativeForce(Vector3.forward*fwdspeed);
}
and the problem is that it moves like it should but after a while it slows down, moves forward again, then slows down again, then even moves backwards, then forwards again and so on. What is this? I tried using different physics materials and removing them, did not help.
Answer by clunk47 · Jan 02, 2013 at 09:16 PM
Don't use Relative Force. Relative is local direction. Just use AddForce to use world coordinates. If it's slowing down, turn down the rigidbody's drag to 0, angular drag to 0, and in script use rigidbody.MaxAngularVelocity = 100; 7 is default, 100 will make sure you have no rolling problems. Drag is what slows things down. You could also check out constantForce.force
O$$anonymous$$, seems like it all works as it should. I changed it to addforce and made it on Start ins$$anonymous$$d of update because it would make it go faster with every frame. then I had to set the force 100 times bigger so it would move at a normal value, is that okay? and what exactly is that maxAngularVelocity (apparently its max, not $$anonymous$$ax) the sphere would be slowing down but that max fingy makes it work just right. thank you
max angular velocity is how fast rigidbodies can rotate, or "roll", kinda like torque. Glad I could help :D
Answer by Drakmyth · Jan 02, 2013 at 09:01 PM
I'm somewhat new to Unity and haven't really fiddled with the physics system yet, but my guess is that as the sphere rolls, it's relative coordinate system is rolling with it. Because you're applying the force relatively, it is using that constantly changing coordinate system to apply the force. Thus, each time FixedUpdate runs, your sphere will move in whichever way it's forward direction happens to be facing, which is not necessarily the same direction as it was in the editor. I think what you really want to use is rigidbody.AddForce(), as that should use the global coordinate system, which will stay constant regardless of the movement of your sphere.
yes, I've already tried AddForce().. It would make a different problem but clunk47 helped me solve it. Thank you.