2D Collision Detection

Hello everyone,

I am trying to create a new 2D game. Due to some constraints, I cannot use the sprite system, and have to use images. How would I use collisions in this case?

There is a Playcanvas integration script with p2.js, that is a 2D physics (and collisions!) library which is quite fast and handy for 2D games.

Take a look here:

2 Likes

Hey @Leonidas, thanks for the response. How would I get the upper object to move based on the lower object’s rotation in https://launch.playcanvas.com/866438?debug=true? Should happen via gravity, doesn’t in p2. Use left and right arrow keys to move.

You can do that by removing any physics/collision p2 scripts from the top entity and then adding it as a child to the bottom entity.

Now when the bottom entity moves or rotates the top entity will be transformed as well.

1 Like

I don’t mean that @Leonidas. What I meant was that if the bottom image rotated in such a way that the top image faces the point of the rectangle, the top image should normally fall off since it is unbalanced. Any way to implement this? It works in ammo.

Looks like you are rotating the entity but not the p2 collision ‘shape’. Have a look through the integration script and the p2.js API to see how to rotate the p2 body.

1 Like

Thanks, will do.