So im pretty new to godot and im trying to let my player rotate smoothly in the direction hes moving to.
Right now he just clips between the 8 possible moving directions, so im basicly trying to have a smooth transition between those directions. I tried a couple different things but none of them worked, most of the time the character just rotates permanently or in random directions
<code>extends CharacterBody3D
const NormalSpeed := 180
const SprintSpeed := 360
const SneakSpeed := 90
const fall_acce := 60
const jump_impulse := 1000
var target_velocity := Vector3.ZERO
#-------------------------------------------------------------------------------
func _physics_process(delta):
#Stores the input direction
var direction := Vector3.ZERO
#just checking for input and BASIC moving based on that
if Input.is_action_pressed("m_forward"):
direction.x += 1
if Input.is_action_pressed("m_backward"):
direction.x -= 1
if Input.is_action_pressed("m_left"):
direction.z -= 1
if Input.is_action_pressed("m_right"):
direction.z += 1
#Normalizing
if direction != Vector3.ZERO:
direction = direction.normalized()
$Pivot.basis = Basis.looking_at(direction)
if not is_on_floor():
target_velocity.y = target_velocity.y - (fall_acce * delta)
#Extra Movement
#Sprint
var speed: int
if Input.is_action_pressed("m_sprint"):
speed = SprintSpeed
else:
speed = NormalSpeed
#Sneak
if Input.is_action_pressed("sneak"):
get_node("CollisionShape3D").disabled = true
speed = SneakSpeed
else:
get_node("CollisionShape3D").disabled = false
#Jump
if is_on_floor() and Input.is_action_just_pressed("jump"):
target_velocity.y = jump_impulse * delta
target_velocity.x = direction.x * speed * delta
target_velocity.z = direction.z * speed * delta
velocity = target_velocity
move_and_slide()
</code>
<code>extends CharacterBody3D
const NormalSpeed := 180
const SprintSpeed := 360
const SneakSpeed := 90
const fall_acce := 60
const jump_impulse := 1000
var target_velocity := Vector3.ZERO
#-------------------------------------------------------------------------------
func _physics_process(delta):
#Stores the input direction
var direction := Vector3.ZERO
#just checking for input and BASIC moving based on that
if Input.is_action_pressed("m_forward"):
direction.x += 1
if Input.is_action_pressed("m_backward"):
direction.x -= 1
if Input.is_action_pressed("m_left"):
direction.z -= 1
if Input.is_action_pressed("m_right"):
direction.z += 1
#Normalizing
if direction != Vector3.ZERO:
direction = direction.normalized()
$Pivot.basis = Basis.looking_at(direction)
if not is_on_floor():
target_velocity.y = target_velocity.y - (fall_acce * delta)
#Extra Movement
#Sprint
var speed: int
if Input.is_action_pressed("m_sprint"):
speed = SprintSpeed
else:
speed = NormalSpeed
#Sneak
if Input.is_action_pressed("sneak"):
get_node("CollisionShape3D").disabled = true
speed = SneakSpeed
else:
get_node("CollisionShape3D").disabled = false
#Jump
if is_on_floor() and Input.is_action_just_pressed("jump"):
target_velocity.y = jump_impulse * delta
target_velocity.x = direction.x * speed * delta
target_velocity.z = direction.z * speed * delta
velocity = target_velocity
move_and_slide()
</code>
extends CharacterBody3D
const NormalSpeed := 180
const SprintSpeed := 360
const SneakSpeed := 90
const fall_acce := 60
const jump_impulse := 1000
var target_velocity := Vector3.ZERO
#-------------------------------------------------------------------------------
func _physics_process(delta):
#Stores the input direction
var direction := Vector3.ZERO
#just checking for input and BASIC moving based on that
if Input.is_action_pressed("m_forward"):
direction.x += 1
if Input.is_action_pressed("m_backward"):
direction.x -= 1
if Input.is_action_pressed("m_left"):
direction.z -= 1
if Input.is_action_pressed("m_right"):
direction.z += 1
#Normalizing
if direction != Vector3.ZERO:
direction = direction.normalized()
$Pivot.basis = Basis.looking_at(direction)
if not is_on_floor():
target_velocity.y = target_velocity.y - (fall_acce * delta)
#Extra Movement
#Sprint
var speed: int
if Input.is_action_pressed("m_sprint"):
speed = SprintSpeed
else:
speed = NormalSpeed
#Sneak
if Input.is_action_pressed("sneak"):
get_node("CollisionShape3D").disabled = true
speed = SneakSpeed
else:
get_node("CollisionShape3D").disabled = false
#Jump
if is_on_floor() and Input.is_action_just_pressed("jump"):
target_velocity.y = jump_impulse * delta
target_velocity.x = direction.x * speed * delta
target_velocity.z = direction.z * speed * delta
velocity = target_velocity
move_and_slide()
New contributor
Aluxus Alex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.