x


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?

more ▼

asked Oct 05 '10 at 08:39 PM

Tuah gravatar image

Tuah
153 22 23 29

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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.

more ▼

answered Oct 05 '10 at 09:01 PM

skovacs1 gravatar image

skovacs1
10k 11 25 91

@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!

Dec 22 '10 at 04:49 PM Jesus_Freak
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Oct 05 '10 at 09:00 PM

burnumd gravatar image

burnumd
3.3k 22 34 71

@Francis Fernandez, yes very true,thanks for clearing this out.

Jul 27 '12 at 11:27 AM Fady-S
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1882
x1799
x292
x83
x10

asked: Oct 05 '10 at 08:39 PM

Seen: 8639 times

Last Updated: Jul 27 '12 at 11:27 AM