Simulating a ( sort of ) magnetic attractor

Jul 18, 2010 at 4:45 PM

Hi everibody.

First of all, I think OOPS is areally well done library, in comparison to other engines in term of object roeined design.

Then the question: I would like to simulate an object to be attracted by some other with some kind of field: What is the best way to achiebve this ?

I'm think on just adding to the rigid body my "field" component in the update function, but no idea if there is some better way.



Jul 24, 2010 at 7:57 PM

Hi felixpollan,  Here's one way you could do it:

Subtract the positions of the rigidbodoes:

Vector3 normal = rigidBody1.Position - rigidBody2.Position;

Normalize the vector:



Then, use this normal to apply a force to both rigid bodies:

normal *= <some factor>;



Jul 24, 2010 at 9:41 PM

hanks you very much,

I will try