Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Magnet Script?

Discussion in 'Scripting' started by Kripto, Apr 4, 2008.

  1. Kripto

    Kripto

    Joined:
    Feb 12, 2007
    Posts:
    119
    Hey everybody,

    Just fooling around with writing a script which would turn an object into a magnet that would effect on certain other objects. Anybody have any suggestions to how this could be done?

    I'm currently pursuing the idea of using the 'Add Explosive Force' example code with a negative force applied to objects in the effect sphere.

    And other ideas?

    Thanks!
     
  2. Tom163

    Tom163

    Joined:
    Nov 30, 2007
    Posts:
    1,290
    Some rough ideas:

    Use a "is magnetic" tag or layer.

    Put a large invisible sphere collider around the magnet, make it a trigger, use its OnTriggerStay() function. This way you only have to test against nearby objects.