June 2018
Beginner to intermediate
298 pages
7h 38m
English
When a KinematicBody2D is moved with move_and_slide(), it may collide with more than one object in a given frame. For example, when running into a corner, the character may hit the wall and the floor at the same time. You can use the get_slide_count() method to find out how many collisions occurred, and then get information about each collision with get_slide_collision().
In the case of the Player, you want to detect when a collision occurs against the Danger TileMap object. You can do this just after using move_and_slide() in Player.gd:
velocity = move_and_slide(velocity, Vector2(0, -1)) if state == HURT: return for idx in range(get_slide_count()): var collision = get_slide_collision(idx) if collision.collider.name ...
Read now
Unlock full access