#Ramps with MoveAndSlide()

1 messages · Page 1 of 1 (latest)

calm hollow
#

Hello! I am working on an arcadey skating game prototype (haven't decided what type of skating, but that doesn't really matter at the core).

I thought I had the basic movement down until I tried a much steeper ramp than the ones I been trying previously.

Shallower ramps seem to work perfectly - I use the following code to snap the CharacterBody3D to the group. I use 3 raycasts to determine the normals (see attached image).

 private Transform3D AlignWithY(Transform3D newTransform, Vector3 newY)
 {
     newTransform.Basis.Y = newY;
     newTransform.Basis.X = -newTransform.Basis.Z.Cross(newY);
     newTransform.Basis = newTransform.Basis.Orthonormalized();
     return newTransform;
 }```

```c#
public override void _PhysicsProcess(double delta)
{
    ...
    if (IsOnFloor())
    {
        // normal avg
        Vector3 normal = (frontRay.GetCollisionNormal() + middleRay.GetCollisionNormal() + backRay.GetCollisionNormal()) / 3.0f;
        Transform3D newTransform = AlignWithY(GlobalTransform, normal);
        GlobalTransform = GlobalTransform.InterpolateWith(newTransform, 12.0f * (float)delta);
    }```

The problem I am encountering is that when I am moving up steeper ramps (as shown in the attached image), the movement is very choppy as the CharacterBody3D thinks that it is NOT on a floor or wall, so gravity is applying.

What I want is smooth movement up and down the ramp; essentially, I want the movement on ramps/slopes to feel no different than moving on flat ground. Of course, I'll work on momentum and stuff later, but for now, I just want to stick to the basics.

Does anyone have any ideas for a better approach or how I can correct the jankiness of the current setup? Also, would it better to not use a box collider for this?
wild hill
#

You can simply disable gravity when touching a ramp.

Or/and you may want to change "floor_max_angle" for the CharacterBody3D

clear jacinth
calm hollow
calm hollow
# clear jacinth You can try setting the CharacterBody3D's `up_direction` to the raycast's hit no...

@clear jacinth this worked pretty well! thank you very much!

I do have one more question - although it continues to think I am on the floor (biggest issue fixed, thanks again!!), it looks a bit choppy as I move up this ramp. I suspected that it's because it's very steep and that I'm using a box collider, but that isn't it as I tested it with a sphere as well. So I definitely think it's something with the way I'm snapping to the normal.

Do you have any suggestions for how to get around this?

wild hill
calm hollow
wild hill
#

The only other idea i have is making the ramp smoother and increasing the max amount of collisions per frame in the CharacterBody

Either that or checking the distance between collision points and interpolating based on that.
So it doesn't just go "between the last 2 normals" but it also takes into account how much it should care about each.