Hello! Happy to be here 🙂

I am working on a top down 3D game using Godot 4.X and, since I am new to programming and Godot, I followed Lukky's tutorial on creating a character controller. The result is great, but the rotation of the character is a bit stiff, popping from one direction to another, specially when using keyboard (WASD). Any suggestions on how I could smooth out the rotations better?

`
extends CharacterBody3D

const SPEED = 2.5
const JUMP_VELOCITY = 4.5
var isWalking = false

# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
@onready var animation_player = $Visuals/mixamo_base/AnimationPlayer
@onready var visuals = $Visuals

func _ready():
animation_player.set_blend_time("idle","walking",0.2)
animation_player.set_blend_time("walking","idle",0.2)

func _physics_process(delta):
# Add the gravity.
if not is_on_floor():
	velocity.y -= gravity * delta

# Handle Jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
	velocity.y = JUMP_VELOCITY

# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var input_dir = Input.get_vector("left", "right", "forward", "backward")
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
	velocity.x = direction.x * SPEED
	velocity.z = direction.z * SPEED
	visuals.look_at(direction + position) 
	
	if !isWalking:
		isWalking = true;
		animation_player.play("walking")
else:
	velocity.x = move_toward(velocity.x, 0, SPEED)
	velocity.z = move_toward(velocity.z, 0, SPEED)
	if isWalking:
		isWalking = false;
		animation_player.play("idle")

move_and_slide()

`

Forni changed the title to How to Smooth Turns on 3D Character Controller? .

Instead of directly setting direction, make your own variable _target_direction and set that. Then rotate toward _target_direction a set amount in your process.

    award

    Thanks for the reply! Sorry I am a bit of a novice in coding, that is what I tried without a good result:

    var futurePos = position -direction
    var positionLerp = position.lerp(futurePos,10)
    visuals.look_at(positionLerp)

    I am problably doing it wrong hehehe, what would be the best way to accomplish this?

    Thank you! 🙂

    PS: Oh, I am onlu using -direction because I made my scene on the inverted axis. Godot forward is -z, I guess? hahaha