- Home /
Add Relative Force
So I've been working on this incredibly complex control system only to discover "addRelativeForce" and facepalm.
Say I have a rigidbody sitting on a moving object, and I want it to move at a goal speed in relation to the object it's on. (For example, character run at 10mph + the train's speed of 40mph.)
From what I understand, using addForce for this will simply make my character attempt to reach a grand total of 10mph, whereas addRelativeForce will make my character attempt to reach 10mph + the train's speed.
Is this about right?
Answer by skovacs1 · Oct 05, 2010 at 09:01 PM
No, not quite.
AddForce adds force in world coordinates and AddRelativeForce adds force in local coordinates.
rigidbody.AddForce(transform.forward * 10);
is the same as
rigidbody.AddRelativeForce (Vector3.forward * 10);
If you have a rigidbody sitting atop a moving object, the amount of force transferred from the the moving object to the rigidbody is determined by the amount of friction on both of the objects' collider's physic material, the amount of force pushing the body against the moving object and the mass of the rigidbody. If you have no friction, you would have to add the force of the moving object while they are in contact.
AddForce will always add force. If you are moving with the same forces as the train (however you decide to achieve this), when you AddForce on top of that, you will be moving with that much more force than the train.
Force is not measured in units of velocity(distance/time), but in units of Force (Newtons or whatever). Applying a force doesn't necessarily apply enough force to reach velocity x except in a completely empty and appropriately setup system because of things like drag, surface interactions and constant forces and the like which will affect velocity in different ways. With drag, the rigidbody will slow to a stop as it moves. Physic materials and collisions can easily have a wide variety of effects on velocity from bouncing back with equivalent force to friction adding the velocity of whatever was collided with.
@skovacs1: thanks for explaining that to them, because this is the first post i saw with the subject, and i wanted to know how to add force in local coords, and you helped me understand how... thanks!
Answer by burnumd · Oct 05, 2010 at 09:00 PM
Not really. AddRelativeForce
has more to do with the direction of the rigidbody you're adding force to rather than the magnitude of force. characterRigidbody.AddForce (0, 0, 1)
will push your character in the global z-direction. characterRigidbody.AddRelativeForce (0, 0, 1)
will push your character forward based on which direction your character is facing (whichever way the blue arrow points when select the character and have "Local" selected as the coordinate system in the editor). In both cases, you must still determine the amount of force by multiplying the normalized direction by the magnitude of force.
@Francis Fernandez, yes very true,thanks for clearing this out.
Your answer
Follow this Question
Related Questions
add force to object that has 2 different rigid bodies 0 Answers
Simple Rigidbody / force question 3 Answers
How to apply uni-directional force to a rigidbody 0 Answers
chain and 3rd person character 0 Answers
relativeVelocity how to? (noob question) 2 Answers