- Edited
Hello. I've been working on a character controller in C# using a CharacterBody3D. I noticed that the character is not moving consistently on slopes diagonally:
As you can see in the video the character's diagonal movement on the ramp is different than on the ground. The angle the player moves on the slope appears to be different than when on a flat surface. The ramp's rotation transform is 70° on the x-axis.
Here is what I have for the Player script so far:
using Godot;
public partial class Player : CharacterBody3D
{
public float speed = 1.25f;
public float gravity = 180.0f;
private Vector3 velocity, direction = Vector3.Zero;
public override void _Process(double delta)
{
}
public override void _PhysicsProcess(double delta)
{
//Get Movement Input
direction.X = (Input.GetActionStrength("Right") - Input.GetActionStrength("Left"));
direction.Z = (Input.GetActionStrength("Backward") - Input.GetActionStrength("Forward"));
//Normalize Vectors
if(direction != Vector3.Zero)
{
direction = direction.Normalized();
}
velocity.Y = 0f;
//Left & Right Movement
velocity.X = direction.X * speed;
velocity.Z = direction.Z * speed;
//Apply Gravity
if(!IsOnFloor())
{
velocity.Y = -gravity * (float)delta;
}
//Apply Velocity Movement
Velocity = velocity;
MoveAndSlide();
}
}
Here are the properties for the CharacterBody3D:
Here's a screenshot of the scene w/ the CollisionShape3D:
I'm not exactly sure where the issue is stemming from. If anyone knows why/where this is happening I'd greatly appreciate the input.