Since nesting a CharacterBody2D within another breaks physics, how would i accomplish this?

Godot Version



I wanted to implement a tripping mechanic into my game, where if the character walks off a ledge past a certain threshold it triggers a tripping animation.
My first idea was to create an area2d in the environment with collision boxes next to every ledge, which when entered would trigger the tripping animation. This worked, but i did not like it and it did not seem efficient in the slightest, so i brainstormed other ways to do it.
My next idea was to create an area2d within the character itself with collision boxes near the horizontal edges at the feet, where i would utilize is_on_floor to call the animation. That was when i learned that is_on_floor can only be called by CharacterBody2D. I didn’t think much of it, changed the area2d node to a CharacterBody2D, aaand my character is now infinitely accelerating upwards with seemingly no remedy. The only thing i found was a Reddit post detailing the same issue:
So now i can’t think of any other way to implement this, aside from resorting to the degeneracy of manually putting a collision box next to every edge, which i’m only okay with doing if there really is no other option. Any ideas?

Shoot raycasts down. One in front of the character, one is the middle of it. If the front raycast doesn’t hit anything while the middle one does, it means that the character is standing near/on the ledge.

1 Like

wow, raycasts are such an intuitive solution, thanks a lot!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.