playMaker

Author Topic: How do I detect a collision from above and/or below and ID what hit?  (Read 3663 times)

4ppleseed

  • Full Member
  • ***
  • Posts: 226
Hi guys,
Lets say I have a 2D red square and a blue square drops down and hits the red square on its top & at the same time a green square hits from the bottom. What's the simplest way to identify both collisions and provide two different events?

Is it possible not using rigidbodies? How do I tell which one hit from the top and which from the bottom?

I've been trying all sorts of different combinations this afternoon (rigid, kinematic, triggers, box colliders etc etc) and I can't get it to work  :o

VectorF22

  • Junior Playmaker
  • **
  • Posts: 50
Re: How do I detect a collision from above and/or below and ID what hit?
« Reply #1 on: July 21, 2013, 06:43:47 PM »
Hi,

I'm not sure how you would do this in playmaker without rigid bodies, but the easiest way would be to set up various collision events on each square with tags checking for each corresponding colour...

So, each colour square would be tagged with their own colour... Red with a 'red' tag, and so on...

Then when the red square hits the blue square, the collision event on the red square that checks for the 'blue' tag will be fired, go to the next state and do whatever you need it to!

You might have to be careful about doubling up using this technique though... because if you have the same collision events on the blue square, then a corresponding 'red hit collision' is going to happen on that too...

Hope this helps!

4ppleseed

  • Full Member
  • ***
  • Posts: 226
Re: How do I detect a collision from above and/or below and ID what hit?
« Reply #2 on: July 25, 2013, 06:48:58 PM »
How about with rigidbodies but determining where they have collided. Top of the square, left side etc... ?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How do I detect a collision from above and/or below and ID what hit?
« Reply #3 on: July 29, 2013, 07:09:38 AM »
Hi,

You could compare the position of the collider against the position of the object that collided, then you know if it's below, on the left etc. I would simply have several colliders attached to a single gameObject, and then it's a lot easier. You implement collision detection on each of your colliders, act upon them, AND you can also simply forward a collision event to a parent to handle all cases for that mesh if you want to.

bye,

 Jean