Magnets

Okay, I’m having a bit of trouble with this one…I have an object (a box) with a simple ball rolling around it. I want to be able to create a “magnet” out of that box so that it attracts the ball to it when the ball comes within a certain range of the box…

I did find this but i don’t know if i’m implementing it wrong or something…i have it attached to the box, both objects have a rigidbody but nothing happens!

http://www.unifycommunity.com/wiki/index.php?title=Gravity

here is some code that should help you will have to tinker with it to get it to work on your project but it should put you hopefully on the right track

[/code]

//note when creating magnets the object attracted to the magnet must have a collider and arigidbody attatche to it for it to work.also check out its mass 200 seems to work ok with a drag factor of 1

var radius = 30.0;
var power = -10.0;

var strength = .5;
function Update (){

// Applies an explosion force to all nearby rigidbodies
var explosionPos = transform.position;
var colliders : Collider[ ] = Physics.OverlapSphere (explosionPos, radius);

for (var hit in colliders) {
if (!hit)
continue;

if (hit.rigidbody hit.tag == “towermagnet”) //dragonhometag

{
hit.rigidbody.AddExplosionForce(power, explosionPos, radius, 0.0);
}
}
}