2D Collision Detection Issue (SOLVED)

Alright, I’ve spent a few hours on this one and could use some help…

I’ve gone off of the War Battles tutorial and made a simple 2-D game where a sprite walks around a level. Right now, the sprite walks through any of the layer 2 objects in the tilemap, however, and there’s no collision detection.

I’ve gone through this manual: https://www.defold.com/manuals/physics/#_tilesource_collision_shapes and set everything up correctly, as far as I can tell. Both the player and the tilesource have collision objects associated with them that should be masking each other. I’ve put a few screenshots of the windows below.



If anyone can help me figure out where I’m going wrong, I’d really appreciate it.

It looks ok. What if you open game.project and check the Physics Debug checkbox to visualise the collision shapes. Does it look ok while running?

TIL about the physics debugging feature… Nice!

Here’s what I’m looking at:

Ok, the shapes are there. And you’re not getting anything at all when moving the player on top of the trees? You’re welcome to share the project with me (bjorn.ritzl@king.com) and I’ll take a look.

Now I’m getting an issue where I’m unable to move the poor guy. Let me see about figuring out how to share this your way…

I’m able to move him around when changing the collision type for the player collision object to dynamic, so I’m suspecting that the issue has something to do with the way the game is handling him moving as a dynamic collision object.

On collision object ‘world’ group should be ‘world’ and mask should be ‘player’. And may be ‘dynamic’ is not what you want for your ‘player’ object.

2 Likes

I must’ve changed those during debugging…

However, you’re right! Changing the collision type to kinematic, then dropping in a quick function to handle collisions seems to have fixed the issue. Thank you much!

EDIT: The collision seems to work, but the sprite seems to get “stuck” after running into one of the collision-marked tiles…

Just some code issues. All straightened out now.

Thanks for the help, folks!

2 Likes

Kinematic collision objects = You control the movement of the game object and get all collision messages so that you can resolve collisions yourself
Dynamic collision objects = The physics system handles movement and collision resolution. You still get collision messages though. You can manipulate the object my applying force to it.

@seven_r

What did you use to fix your “stuck” problem? I’m having a similar issue and I’m wondering where it is I’ve gone wrong