- Edited
Hello! I'm currently working on a game where the player (CharacterBody3D) is often on ramps. I'm aligning the player to the surface using raycasts and the returned normals (the barymetric way). Here's my problem:
This is what I want (green line) vs. what is actually happening (red line) - excuse the crude drawing:
As I drew in the close up, the raycast hits the edge, which then triggers to player to snap to that collision point. What I want to do is prevent the player from snapping to the corner (red arrow), and instead continue upwards (green arrow).
I attempted to use angle_to()
between the current normal at the player's position and the collision point. I set the condition to if the angle is >=90 degrees, do not perform the surface alignment - but I'm getting inconsistent results depending on the surface itself (primitive vs array mesh geometry). I'd also like to have a bit more flexibility modifying this behavior based on the player's speed, etc.
Put simply - I am looking for a way to detect when the player is about to hit a sharp edge.
Are there better/more flexible ways to accomplish this than using angle_to()
? Specifically, should I use other colliders/raycasts to detect this?