Sign in to follow this  
Yanifska

How to add a sensor in p2

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 ?

Share this post


Link to post
Share on other sites

http://test.xapient.net/phaser/ALL/moving-jumpthrough-platform-2.html  this is one of my first experiments to get jumpthrough platforms to work.. i used two sensors..   the above one disables collision on contact and the lower one enables it...   maybe you could read the code and find out what you want ?

Share this post


Link to post
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...

Share this post


Link to post
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!

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.