0 votes

I have a KinematicBody2D player node for which I check is_on_floor(), is_on_wall() and is_on_ceiling() in each iteration of the physics loop and execute the appropriate code, which works well when colliding with genuine floors/walls/ceilings.

The problem is that the enemies (also KinematicBody2D nodes) cause these functions to return true when the player collides with them. I only wish for the code I've written to execute when the player collides with genuine floors/walls/ceilings (which I've identified by adding them to a dedicated collision layer).

Is there any way to easily get the collider which caused the engine to return true when is_on_floor was called (if there are multiple, just the first would be fine)? If not, is my only option to put raycasts and do a manual check, effectively eschewing the is_on_thing approach?

Godot version v3.2.3.stable.official
in Engine by (63 points)

2 Answers

+1 vote

Thank you, I sought precisely this.

0 votes

If you use move_and_collide the result is a KinematicCollision (https://docs.godotengine.org/fr/stable/classes/class_kinematiccollision.html#class-KinematicCollision) and allows you to check the collider.

If you use move_and_slide() or move_and_slide_with_snap() though, you can't access the collider. If would suggest to add an Area2D with a slightly larger collision shape. With the Area2D_body_entered signal you can check the body that's colliding with you.

by (627 points)
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.