playMaker

Author Topic: Push/Pull Setup  (Read 3393 times)

k2kshard

  • Playmaker Newbie
  • *
  • Posts: 9
    • View Profile
Push/Pull Setup
« on: February 21, 2013, 10:45:51 PM »
Hi,

I have two objects that when they get within a set radius I would like to either Repel them, or Bring them together based on their 'charge' or positive or negative (Magnet in a sense, although doesn't have to be real world accurate)

Currently I have got it so that when one object enters the others 'radius' it does a test to see if they are opposite or matching, and then moves into each relevant state (of isMatching, isOpposite).

In these states I plan to perform the push/pull, but I havent found a workable solution for this yet..

If I use Add Force it advises I need Rigidbody, I have the objects setup that the actual 3d model has Rigidbody, but the FSM is triggered by entering a 'trigger' which if I have Rigidbody on, it doesnt move..

Any ideas? Better way to set this up?

Thanks

greg

  • Junior Playmaker
  • **
  • Posts: 68
    • View Profile
Re: Push/Pull Setup
« Reply #1 on: February 22, 2013, 09:41:07 AM »
Not sure what you mean with your setup so i'll throw out various functions you could play with:

 - "get distance" to get the distance between two objects
- "move" functions
- parent objects to get them exactly follow one another
- you could get angle between the two objects, then invert it, then move objects away to repel
- you could use "look at" to make object look at close by object, then move it negative on its Z axis to repel it

Hope that helped :)

Red

  • Hero Member
  • *****
  • Posts: 563
    • View Profile
Re: Push/Pull Setup
« Reply #2 on: February 22, 2013, 04:44:43 PM »
Aaah, yeah... i've had rigid-bodies and all that happen too.

the way i work around it is add an empty game object to the scene, tell it to be a child of the object you want and then add a collider component to it. from there i just make sure it's the right one and have a simple fsm where it detects when the trigger has been fired off and sends an event to the parent's FSM that handles these kinds of things.

So,

MainObject
-Collider (resetting the transformation matrix though is a good idea so that you can have it at the 0,0,0 position, rotation and scale... and using the scaling in the collider to determine the size.)

when collider is hit, it tells it's parent that it's been hit and if you use the trigger event action you can even tell it more information with the "Set FSM" actions which work on the values extracted with the trigger event action itself.

I'm not sure this is the best way to do it but it's one way i've done it (though, being able to stack multiple colliders on the same object would be nice... one for rigid-body stuff and another for things like radar, activation, etc... the usual stuff you'd use a trigger for but that's a limitation of unity and not playmaker.)

k2kshard

  • Playmaker Newbie
  • *
  • Posts: 9
    • View Profile
Re: Push/Pull Setup
« Reply #3 on: February 24, 2013, 06:13:51 PM »
Hi Guys,

Thanks for the feedback - Some good suggestions..

At the moment the problem is getting the 'parent' (the actual 3d mesh) object to move..

"- you could get angle between the two objects, then invert it, then move objects away to repel
- you could use "look at" to make object look at close by object, then move it negative on its Z axis to repel it"

Think those + Red's setup might be the best starting point for me :)

Will see how I go!

Red

  • Hero Member
  • *****
  • Posts: 563
    • View Profile
Re: Push/Pull Setup
« Reply #4 on: February 25, 2013, 01:44:12 PM »
also, for moving items, don't forget to consider these actions.

-Translate (you can use this to translate the positional data of an object either over time, per second or while the action/state is firing off)
-Move Towards (you can tell it to move towards a specific vector position or a game-object. this one will let you determine the speed at which it travels.
-iTween (a lot of actions... they may be intimidating at first but they're pretty good... only downside is that they are contained actions so updating information on the fly is tricky. it's usually best to use these for specific motion such as doors opening, closing, sliding, etc...)
-Set Position (though this is mainly a "do it now" kind of action if you are not concerned with a smooth movement path this might do the trick... if you don't want a nice smooth path, this is probably the most efficient way of approaching it since it'll fire off once and do a very specific, single act of setting the object's position to what you want it to be. basically, it's an instantaneous thing.)

I wouldn't be surprised if there were more... but, i'm certainly not a pro and i'm always learning new things every day. (i don't know if i ever will be a master at this... but, that's fine... so long as i know enough to get done what i need to get done. :))