playMaker

Author Topic: MAGNET  (Read 3411 times)

Nazca

  • Playmaker Newbie
  • *
  • Posts: 4
MAGNET
« on: January 14, 2013, 01:47:24 PM »
DISCLAIMER: NOOB QUESTION AHEAD

Hi everyone!

I try to explain the problem i ran into.

I have a sphere (with rigidbody), a trigger, and a moving empty gameObject (which I'd want to act as a magnet with the sphere).

In other words, I am trying to have the magnet attract the sphere when the sphere enter collision (and stay in collision) with the trigger, until it snap together with the magnet (create a joint connection between them)

Could anyone point me in the right direction to create the above?

Thanks in advance to everyone!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: MAGNET
« Reply #1 on: January 14, 2013, 02:10:27 PM »
Hi,

 Have you checked this from the asset store:

http://www.coffeeshopphysics.com/magnetodynamics/

else, I suspect it is quit involving to do such thing mathematically, tho there seems to be a good code here:
http://answers.unity3d.com/questions/20544/magnet-code-from-c-to-javascript-can-i-make-it-aff.html

as for the final "lock" I would simply attached a "fixed joint" component to bind the two objects together, but your hardest part will be to build the magnetism feature.

bye,

 Jean

Alio

  • Playmaker Newbie
  • *
  • Posts: 19
Re: MAGNET
« Reply #2 on: January 14, 2013, 04:55:57 PM »
You can create another FSM for those objects to trigger on "on trigger enter" where once that happens it triggers event to have that object which is being pulled do a "move towards" at a very slow speed to make it appear that it is getting pulled by magnetism. if that object is something you can control as long as you set the move towards speed less than your movement speed you will be able to move away from the trigger zone.

Be sure to set also a on trigger exit which when set off will set the move towards event to off so that you are not always having to move towards that object once you leave the trigger area of the magnetism.

Like jean said you can create a "fixed joint" or empty game object attached to the magnet.  This will be the point that your attracted item moves towards.  Once it gets to that location or within a x amount of distance have it send event to parent joint to it. now it should be a child of that "fixed joint" where it will give the effect that the magnet has complete control of it and anywhere the magnet moves that object will as well.  sent unparent event to reverse process.  This should work but it seems a bit messy.
I just frankenstein it.