Can i add 2 collisions detection to one physics body?

So i have a circle and i need to detect 2 type of collision on it… I attched the circle… So when soemthing collides with the red part something happens and when something collides with the blue part somthing happens…

Is this possible??

Thanks!!

Note: I have a radius on the circle for the physics body…

Anything is possible, but that is really not a good idea.

You’d be adding, complexity and ambiguity which will bite you in the butt later.

Please show both listeners as you wish them to be logically ordered and I’ll see if I can help you compose them as one.

-Ed

Question: How do you know if you hit the blue part or the red part?  Is that what you’re really trying to figure out?  If so, a new plugin should be able to help:

https://store.coronalabs.com/plugin/math2d

That exactly the question I’m asking… And the plugin ; how would that help me??

http://github.com/roaminggamer/RG_FreeStuff/raw/master/myPluginSamples/math2d/circleRegionCollision.zip

Here is an answer using the math2d plugin.  You’ll have to dig through it to understand.  I don’t have any more time to help on this I’m afraid.  All tapped out.

https://www.youtube.com/watch?v=J2seUtgoBkw&feature=youtu.be

-Ed

Note: The answer I gave uses vector math to solve the problem.  If you do not know vector math you could be in trouble.

However, if you want to make any kind of action or arcade game in 2D (and 3D for that matter) you MUST learn vector math.  

In fact if you want to be a game developer, you must get this skill/knowledge in your tool belt.

Just gotta.

So, my suggestion… grab a book and get crackin.  

In theory (and practice), for this very limited mechanic, you could solve the detect “I hit red or blue” problem using hacks.  I’m not going to tell them to you however because they are BAD BAD BAD, and I really want to encourage you to learn vector math.   :slight_smile:

Haha Alrighty I’ll probably end up reading online and maybe going to the library! Good thing I’m a quick learner! Love math!

Ed’s vector math is a good solution. You could also setup a complex multi-part body like 2 half-circles which would give you two collision points.  There are also some tutorials (see the recent physics tutorial treasurys) that let you do pre-collision testing to detect where the collision will happen.

Rob

Isnt there a way like lets say 

between 200 and 300 pixels == this happens

like on this spinning circle?

Im not sure im thinking straight(tired outa my mind) But maybe this can be a way?

Thanks!

As soon as the point of impact moves, you need vector math to figure out where it is, OR as Rob pointed out, use complex bodies so that the parts rotate and you can detect collisions with each individual body.

Your question is interesting however as, if you follow it through and really try to solve it, you’ll find… vector math is the solution.  I’ll stop saying it, but that is the kind of question that leads to learning this.

Cheers,

Ed

I’m planing to really take your code out part by part and see how everything works… Maybe get a book or 2 on vector math… Also maybe some videos… I was just wondering if there isn’t a simpler way?? Without multiple body’s?.. Because it I want multiple body’s to spin then I’d need enterFrame and what if a body lags… That would be bad… RoamingGamer your way is awesome and difficult but I think best.

If you do a search on youtube for “coding math” you’ll get a series of valuable short lessons that include vector math. The lessons are based on javascript but this should not be an issue. The author is a very good teacher.

Thanks for the suggestion!

When Rob said multiple bodies, he didn’t mean discrete display objects, each with its own body somehow linked.  He meant use the multi-body feature of Box2D as implemented by Corona.

Rob mentioned this too:

https://coronalabs.com/blog/2015/07/07/tutorial-treasury-physics-essentials/

See the tutorial on the above page called:  

Multi-element physics bodies

Anything is possible, but that is really not a good idea.

You’d be adding, complexity and ambiguity which will bite you in the butt later.

Please show both listeners as you wish them to be logically ordered and I’ll see if I can help you compose them as one.

-Ed

Question: How do you know if you hit the blue part or the red part?  Is that what you’re really trying to figure out?  If so, a new plugin should be able to help:

https://store.coronalabs.com/plugin/math2d

That exactly the question I’m asking… And the plugin ; how would that help me??

http://github.com/roaminggamer/RG_FreeStuff/raw/master/myPluginSamples/math2d/circleRegionCollision.zip

Here is an answer using the math2d plugin.  You’ll have to dig through it to understand.  I don’t have any more time to help on this I’m afraid.  All tapped out.

https://www.youtube.com/watch?v=J2seUtgoBkw&feature=youtu.be

-Ed

Note: The answer I gave uses vector math to solve the problem.  If you do not know vector math you could be in trouble.

However, if you want to make any kind of action or arcade game in 2D (and 3D for that matter) you MUST learn vector math.  

In fact if you want to be a game developer, you must get this skill/knowledge in your tool belt.

Just gotta.

So, my suggestion… grab a book and get crackin.  

In theory (and practice), for this very limited mechanic, you could solve the detect “I hit red or blue” problem using hacks.  I’m not going to tell them to you however because they are BAD BAD BAD, and I really want to encourage you to learn vector math.   :slight_smile:

Haha Alrighty I’ll probably end up reading online and maybe going to the library! Good thing I’m a quick learner! Love math!

Ed’s vector math is a good solution. You could also setup a complex multi-part body like 2 half-circles which would give you two collision points.  There are also some tutorials (see the recent physics tutorial treasurys) that let you do pre-collision testing to detect where the collision will happen.

Rob

Isnt there a way like lets say 

between 200 and 300 pixels == this happens

like on this spinning circle?

Im not sure im thinking straight(tired outa my mind) But maybe this can be a way?

Thanks!