You can use a ramp, that's the simplest solution.
In my case I made a stair collision layer and have a ray at player feet level, the ray is aimed forward (multiplied by input direction and player facing), and when it detects a slope, and there's input, it pushes the player up.
It works, you can't tell the difference. But you need to be careful about collision layers and static physics nodes in your scenes.
CharacterBody3D vs stairs
Even AAA companies often use ramps for stairs. There will be collision boxes for the steps as well, but on a different layer for use in IK animation. Not only is a ramp an easier solution, but it also simplifies the physics situation which is good for performance
xyz I see that now. But like @award wrote you need a second collision shape and layer for handling other physics and foot ik. So I wasn't entirely sure whether or not to use one complex collision shape or two, one being a ramp for character movement.
But I guess you need to implement some stair handling as well. You can't force the player to jump on sidewalks etc.
award that is not true. Character controllers tend to have support for stairs.
Bge had stair support, unity had it, source had it, unreal probably has it.
Ramps are mostly used with games that use a physics body for the player, as oposed to a character controller.
It depends on the game, the level design. Some parts can't be faked with ramps.
I gave a solution, it's very easy if you know vectors and keep your level well organized. Maybe I should post some code.
Jesusemora unreal probably has it
It doesn't. Although I am not exactly sure what you mean by "have support for stairs".
You are basically just pushing a collision capsule around and the 3D model and all the animations are kind of like a ghost pantomime sitting in a bird cage. By default they don't react to the world at all. Only the capsule does. I made a test a while ago and all the foot IK stuff you see in that video I had to do myself. (Or at least figure out placement (height) and rotation of the foot. Unreal handles the bone IK.)
You can set parameters for the capsule like the maximum angle it can climb or the maximum step height but that's it. There is no special build-in support for steps.
Toxe maximum step height but that's it. There is no special build-in support for steps
That's exactly it. Godot doesn't have step height on character controller, it has good support for ramps through slopes, which is really good for 2D, but not enough for 3D. It does have some better thing than unity like is_on_ceiling and is_on_wall.
- Edited
Stair handling is trivial to script for kinematic colliders.
So after searching around today trying to implement this in my game and not finding any really great examples, I worked out somewhat of a solution. So far it seems to work well and allows for a threshold to kind of mimic the way it works in Unity. It's written considering you're using a RayCast3D node as a child of the CharacterBody3D(in this case, Pivot is child of CharacterBody3D to handle camera rotation, StairRaycasts is a container Node3D child of Pivot to add additional raycast checks if needed after more testing, and then HeightCheck is the RayCast3D). The parent StairRaycasts is positioned a hair forward from the CharacterBody3D's CollisionShape3D and it's Y Position is set to 1, only reason I'm noting all of this is due to the way the code works basing it off of being at that height. My character controller script uses playerMovementVelocity that is just a variable that gets passed into Velocity for MoveAndSlide() so this is simply increasing it's Y value for the distanceTo between the RayCast3D's position and whatever "floor" it's hitting, if anyone thinks it can help them out but need the full script to make sense of it I can post that but this should be pretty easy to make sense of just looking at the code. Keep in mind this is just something I'm playing with but so far it's handling little differences in terrain quite well and also worked great on a little set of test steps I made, also doesn't seem to cause any negative effect to how the CharacterBody3D handles slopes by default.
// **** TEST CODE FOR STAIR RAYCAST
RayCast3D testray = GetNode<Node3D>("Pivot").GetNode<Node3D>("StairRaycasts").GetNode<RayCast3D>("HeightCheck");
Vector3 testraycollisionpoint = testray.GetCollisionPoint();
float distanceto = testray.GlobalPosition.DistanceTo(testraycollisionpoint);
var collidedwith = testray.GetCollider();
GD.Print("distance to ray collision " + distanceto);
GD.Print("collided with " + collidedwith);
// 1 seems to be a solid value when walking on moveable ground, goes to 0.78 when running into step that can't be climbed
// will need to add threshold to compare 1(normal value) to (how far below 1 to allow step up)
// USING 1 FOR THE Y POSITION OF RAYCAST PARENT HITS GROUND AT 1.00XX, THRESHOLD SHOULD BE IN 0.XX VALUE
float threshold = 0.5f;
//if (distanceto < threshold)
if (distanceto < 1f && distanceto > threshold)
{
GD.Print("should climb step here");
// SHOWS THAT STEP SHOULD BE CLIMBED
// ***** WILL PROBABLY NEED TO ADD CODE TO PREVENT THIS FROM RUNNING WHEN MOVING SMOOTHLY UP A SLOPE ****
playerMovementVelocity.Y = distanceto;
}
- Edited
Gaiseric I did something similiar.
It probably needs some fine tuning (and smoothing) but so far it works as expected.
Is it working well with changing the Y velocity? I didn't even think of that. I just changed the players Y position (that's the part that probably should be smoothed a bit).
Now that I see your comment about slopes: That's something I have to test. I totally forgot about slopes!
@export var step_height := 0.35
@export var stair_ray_offset := 1.1
func handle_stairs(direction: Vector2):
stair_ray.position.x = direction.x * stair_ray_offset
stair_ray.position.z = direction.y * stair_ray_offset
if player.stair_ray.is_colliding():
var collision_point = stair_ray.get_collision_point()
var height = collision_point.y - player.global_position.y
if height <= player.step_height:
player.global_position.y = collision_point.y
EDIT: Okay, for the slopes I will check the normal direction of the ray hit point to ensure that the character only steps on actual stairs.
even in games as advanced as this thing that's been floating around, the stairs STILL use slopes as collision shapes.
there is no escaping the fact computers are too stupid to comprehend stairs.
i apologize for posting IGN on our sacred grounds. i'll never do it again. :(
- Edited
packrat STILL use slopes as collision shapes
In first person perspective, slopes feel much better and there's really no need to simulate stairs. For third person, it's debatable, depends on the style of movement, camera ranges and gameplay. But I think most games would be better off without it.