Sunday, February 26, 2017

Sundays afternoon with Godot: E01-Collisions

Varying the environment is necessary to make the game less boring. I give here some examples implemented in LittleShadows. You'll see how easy it is do that with godot! First, here is the resulting video:


First of all my main character, the little girl, has several collision layers and masks.

It decided to keep it easy however, you'll see how I dynamically manage some bit masks to alter the behavior. The first collision layer is used to collide against the main tiles of the tilemap which is used to create the ground and walls. The two layer masks are used to detect collisions against ennemies and objects. Additionaly, the collision layer no. 4  (and not mask) will be dynamically set when the girl touches the ground and removed when she jumps or the move down button of the joystic is activated.


Stairs: Stairs are important element of a platfetormer game.In the case of LittleShadows, the stairs are distinct elements from the basic tiles used to create the ground which are gathered in a single tilemap. n the contrary the stairs are a special "scene" or node.

In blue you can see the collision shapes of the the tilemap and in red the collision shapes of the stairs. In order to make a smooth transition between the ground and the stair there is a gap between them, allowing the collision shape of the girl to pass in front of the stair without noticing it. If the player wants to move on the stair he or she only needs to jump. The stairs are in collision mask 4 therefore as soon as she jumps the collision is not detected so she can pass through. However as soon as the Ray2d detecting the ground collides with it, the collision layer 4 of the girl is set back to true allowing collision.


Scaffold: The scaffold uses the same principle allowing to get down from it using the move down button of the joystic.

That's all you have to know to set interesting rules of collisions!

No comments:

Post a Comment