Jump to content

How to add a sensor in p2


Yanifska
 Share

Recommended Posts

hI there,

 

I want to use the main body of a sprite for collisions only, for some kind of platform, and add an invisible sensor that will detect collision only on one side of the sprite and trigger a death reaction.

Basically the character can jump on the top of the sprite, but touching the side will trigger the "die" fucntion.

 

 

My question is: Should I use addRectangle ? it seems to work and it adds a "second body".

However how do I detect collision with this second body ?

Also is doesn't seems to collide like the main boddy, so what does the sensor property will do ?

 

Edit: I didn't  set up collision for the sensor, so I guess that's why it is not colliding, so how do I detect collision / overlap from the sensor ?

Link to comment
Share on other sites

thank man,

 

I see you are using onBeginContact

I was trying to use multiple collide functions each one on specific shapes, but it doesn't seems to work, I guess it should be possible since there are way to specify what shape and groups to collide with.

 

I will try your stuff, however I am a bit in doubt because I have collision groups.

In my case the situation is quite opposite, I want each obstacle to have its own sensor

 

Maybe I should have a sensor in front of the character....

That gives me ideas...

Link to comment
Share on other sites

well.. collisiongroups shouldn't be a problem in general unless you would like to have different collisiongroups for different shapes... (what would be great but i guess that's just not possible right now - correct me if i'm wrong please)

 

the function that is called on contact (either through a collisiongroup callback or an onbegincontact event) has to figure out which shape of the body reported the contact and then act on it accordingly..   should work!

Link to comment
Share on other sites

hehe.. maybe..   btw.  i posted this example because i used sensors of course..  but this is by far not the best way to accomplish what i actually wanted to do there.. (the jumpthrough platform) i managed to get it to work with a totally different approach... (just in case someone needs it )  http://www.html5gamedevs.com/topic/6148-the-moving-jumpthrough-platform-sum-up-thread-help-very-much-appreciated/?p=36930

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...