Godot Version
v4.2.2.stable.official [15073afe3]
Question
For some context, this is the first ever thing I’m making in Godot (and the first ever game I’m making)
I’ve got a CharacterBody2D (Player) with a CollisionShape2D, and a StaticBody2D (Level) with several CollisionShape2Ds. I want to detect the moment when the Player collides with any of the individual CollisionShape2Ds in the Level, and have it trigger something.
I’m using move_and_slide(), because I want the player to be able to slide along a surface, but I want them to do this only after having landed and stopped.
I got this working by storing the is_on_wall() values for the previous frame and the current frame, when the previous is False and the current is True, it stops the player, otherwise it lets the player slides. (Motion Mode is set to floating, so “floors” and “ceilings” also return true for is_on_wall())
But this feels like a hacky workaround, and doesn’t work for detecting a new collision while sliding. And, is_on_wall() is kind of inconsistent, sometimes it goes false for a frame after starting the slide.
I imagine I could do something with area2D nodes, since they can detect when something enters them, but it feels unnecessarily inconvenient to need an area2D for every CollisionShape2D in the Level. And they wouldn’t be very accurate, since they’d have to stick out from the CollisionShape2D to detect the Player entering.
I’m pretty sure there’s something I’m doing fundamentally wrong here, considering my inexperience and how complicated this simple of a problem has been to solve. If that’s the case, please let me know.
Edit to describe the desired behavior:
- The player should be launched in a straight line towards the mouse when pressing a “launch” button. This should only happen if the player is on a surface, not in the air.
- The player should stop upon impacting any surface in the level.
- If the launch key is pressed again after landing, the player should be launched again in whatever direction the mouse is
- If the mouse is “behind” the surface is landed on when the “launch” key is pressed, the player should slide across the surface.
- While sliding, the player should not be able to launch itself.
- The player should stop sliding upon encountering any new surface, allowing the player to launch again