Cant understand why my character slowly turns on Y axis with every jump. Can someone help and tell where is mistake? Code is:
extends CharacterBody3D
@onready var character = $"char_body"
@onready var raycast = $"raycast"
@onready var cam_spring = $"cam_spring"
var speed = 5
var jump_velocity = 4.5
var angular_acceleration = 5
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
func _physics_process(delta):
# 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
# Handle movement.
var direction = Vector3.ZERO
direction.x = Input.get_action_strength("move_left") - Input.get_action_strength("move_right")
direction.z = Input.get_action_strength("move_forward") - Input.get_action_strength("move_backward")
direction = direction.rotated(Vector3.UP, cam_spring.rotation.y).normalized()
velocity.x = -direction.x * speed
velocity.z = -direction.z * speed
if is_on_floor() && velocity.length() > 0.2:
character.rotation.y = lerp_angle(character.rotation.y, atan2(direction.x, direction.z), delta * angular_acceleration)
move_and_slide()