Godot Version
Godot Engine v4.4.1.stable.steam.49a5bc7b6
Question
I am trying to make a 2.5D platform game and I am having problem with the slopes, most of the code works fine, but when i’m going down a slope of almost 90 degrees, my character goes faster than it should.
My movimentation code:
var input_dir = Vector3.ZERO
input_dir.x = Input.get_action_strength("Left") - Input.get_action_strength("Right")
input_dir.z = Input.get_action_strength("Down") - Input.get_action_strength("Up")
input_dir = input_dir.normalized()
var direction = (player.transform.basis * input_dir).normalized()
if !player.is_on_floor():
player.velocity.y -= GRAVITY * delta
if direction:
if (abs(player.velocity.x) < topspeed):
player.velocity.x += direction.x * acc * (abs(slope_factor))
else:
player.velocity.x = direction.x * topspeed * (abs(slope_factor))
else:
player.velocity.x = lerp(player.velocity.x, 0.0, 0.3)
if player.is_on_floor():
floor_angle = player.get_floor_angle()
slope_factor = clamp(cos(floor_angle), 0.4, 1.0)
$"../../Sprite3D".rotation.y = 0
$"../../Sprite3D".rotation.z = -1 * player.get_floor_normal().x
$"../../Collision".rotation.y = 0
$"../../Collision".rotation.z = -1 * player.get_floor_normal().x
player.move_and_slide()