wmurphyrd / aframe-physics-extras

🔧Cannon API interface components the A-Frame Physics System
MIT License
27 stars 8 forks source link

collision between static bodies #13

Closed nirajupadhyay11 closed 6 years ago

nirajupadhyay11 commented 6 years ago

Hi,

I am trying to detect collision between two static bodies using physics-collider="ignoreSleep: true" but it does not seem to be working. Here is my codepen - https://codepen.io/nirajupadhyay11/pen/gQraNq

I expect that the red ball will get displaced due to the collision from the green ball.

Also, which event shall I listen for when that collision occurs?

Could you please help?

Thanks, Niraj

wmurphyrd commented 6 years ago

Hi Niraj,

Listen for the event named 'collisions'. In your codepen I see this event firing as expected when the balls overlap.

With cannon physics, a static body will never be displaced due a collision. That's what is 'static' about them - they do not move unless you directly alter their position. If you want to the red ball to respond to forces, it needs to be a dynamic-body

Here is a modified version in which the red ball is displaced and the collisions are logged in the console. Note that you only need one physics-collider on the green ball as it will report anything that green ball collides with.

https://codepen.io/anon/pen/jQMqYw?editors=1011#0