I’m getting the floors normal while on the ground and using the normal for movement code when jumping. But whenever I walk off a ramp it resets to Vector3.UP. I tried making the ramp as thin as possible, but that didn’t work, plus I don’t want paper thin ramps in my game anyway.
#On Floor
if is_on_floor():
#Coyote Time Reset
if velocity.y > 0:
coyote = false
else:
coyote = true
coyote_timer.stop()
#Trimp Setup
normal = get_floor_normal()
#Ground Accel
if dir and velocity.length() < target_speed:
velocity.x = move_toward(velocity.x, dir.x * target_speed, delta * ground_accelaration)
velocity.z = move_toward(velocity.z, dir.z * target_speed, delta * ground_accelaration)
else:
#Gound Deccel
velocity.x = move_toward(velocity.x, dir.x * target_speed, delta * ground_decelaration)
velocity.z = move_toward(velocity.z, dir.z * target_speed, delta * ground_decelaration)
else:
#Midair
velocity.x = move_toward(velocity.x, dir.x * target_speed, delta * air_control)
velocity.y -= gravity * delta
velocity.z = move_toward(velocity.z, dir.z * target_speed, delta * air_control)
#Coyote Time Process
if coyote and coyote_timer.is_stopped():
coyote_timer.start()
#Head Bob Process
bob_time += delta * velocity.length()
if real_vel.length() > 1.0:
spring_arm.transform.origin = lerp(spring_arm.transform.origin, headbob(bob_time, delta), 0.01)
else:
spring_arm.transform.origin = lerp(spring_arm.transform.origin, Vector3.ZERO, 0.01)
#Begin Movement
move_and_slide()
#Jump Function
func jump():
var real_power:float = jump_power * real_vel.length()/3
velocity.y = max(0, real_vel.y) + clampf(real_power, jump_power, jump_power*1.5)
velocity.x *= jump_boost
velocity.z *= jump_boost
if not normal.is_equal_approx(Vector3.UP):
velocity += normal.reflect(Vector3.UP) * real_vel / 2
coyote = false
print(normal)