This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

I'm making a simple 2D platformer.

I have two tilemaps. Tilemap Structures is for walls, ceiling and floor and anything else that the player can't go through.

Tilemap Ramps is for slopes. I want the player to lose control of his character if the character is standing on a slope, so the player slides down with gravity force.

So far, to check if the player can move, I'm using isonfloor() function which detects both tilemaps as floor.

How do I check which tilemap the player is standing on? Is there a different approach that I can use for the sliding mechanic?

in Engine by (15 points)

1 Answer

0 votes
Best answer

When your kinematic character collides, the KinematicCollision2D returned by get_slide_collision() will tell you what you collided with.

Docs: KinematicBody2D: detecting collisions

by (22,191 points)
selected by

Hey sorry for the late reply. I got stuck on teraria update x)

I tried using the code in the docs you linked, but ran into a problem. When my character was standing above both of my tilemaps, that is, between two tiles, it sometimes behaved as if I'm not standing on a floor and instead I'm already on a ramp. However, the collision box kept me standing on the floor and as such, I couldn't move the character.

I'm pretty sure it could be fixed somehow, maybe by using a circle collider instead of a box collider.

In the end, I made three raycast2d nodes on my character (I posted the same question on reddit and got this idea from a user there), one originating from bottom left, second from bottom right and last one from bottom center of the players collision box.

I'm checking the tilemap using get_collider().name and if either of those raycasts collide with my Tilemap for Structures I know I'm on the ground.

Thank you anyways.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.