How do I rotate my character

Godot Version

godot-4, gdscript, 3d, game

Question

`Hey, starting out with a 3d game and I just wanted to know how I can rotate my character towards the direction I’m moving, currently I’m using lerp, but by holding in the direction the character never stops, wanted to know if there’s a better way to tackle this, I have a video where I repeatedly tap the a and d buttons and the cart doesn’t stop rotating. Any Idea on how to help?? here’s the code:

extends Sprite3D

var min_ang = deg_to_rad(0.0)
var max_angle = deg_to_rad(5.0)
var elapsed = 0.0

func _physics_process(delta):
if Input.is_action_pressed(“move_left”):
rotation.y = lerpf(min_ang, max_angle, elapsed)

elif Input.is_action_pressed("move_right"):
	rotation.y = -0.4

else:
	rotation.y = 0
	elapsed = 0.0
	
elapsed += delta * 5

The function lerpf works with a weight, which is supposed to be from 0 to 1. Try move_toward instead.

1 Like

Hey, thank you for the help, I figured out a solution, but still, thank you for helping me out!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.