# A couple of magnet issues...

Hey guys,

I’m looking to create a game with magnets; and I’ve stumbled on a couple of problems.

Firstly I would like the magnetic force to be applied in a direction I choose - i.e. forward from a face.
I’m using explosive force at the moment and can’t work out how to do anything aside from get the force to apply in a radius around the object.

Secondly when I add multiple magnets the explosive force appears to be culmative; so that 1 magnet with a force of say 5, ends up being a force of 50 if I have 10 of those magnets close together. This isn’t the effect I want - as I’d to have the magnets make the player “float” on them if possible.
This leads me to believe that explosive force is not the way to go (which is a shame as it’s very simple = good for me!).

I hope you can help
Thanks
Lonners

[btw I’ve done a search already but nothing seemed to be entirely pertinent to these particular problems]

Sounds like you just need some simple vector math. Given two points, p1 and p2, provided the distance between them is greater than some small threshold value, you can compute the unit-length vector from the first point to the second as follows:

``````Vector3 direction = p2 - p1;
direction.Normalize();
``````

You can then apply a force along ‘direction’ or ‘-direction’ in order to cause one of the objects to attract or repel the other.