Collision #1


From Behind to Front

Today I worked on creating and setting collisions between the game world (World), the player (Player) and the enemy (Enemy)

Without physical collisions there are no blocks preventing you from passing a “wall”, resulting in the player being able to pass through physical elements of the scenario. This needs to be handled well…

The first thing I did was create the appropriate CollisionShape for Player and Enemy, to cover the entire sprite.

Once I tried it I realized that something was wrong.. the player seemed to pass behind the enemy’s feet in a completely unnatural way.. aarghhhh!!

By appropriately setting the collision layers and the y-sort property of the parent node (World) I managed to obtain the effect I wanted: the player naturally passed behind or in front of the enemy, however now there was another problem to solve!

By leaving the shapes in full body there was no margin between the sprites: the player could only pass when the entire sprite was completely in front of the enemy and vice versa from behind… it was horrible!

The solution was to reduce the shape of the player by excluding the head (the part that would therefore NOT collide anymore), and in the case of the enemy, reduce it only to half the body

So finally the effect of passing in front of and behind the enemy seems realistic! YEAAHHH

The next step is to make this damned enemy move!

Leave a comment

Log in with itch.io to leave a comment.