Godot Version
4.4.1
Question
Hello all,
I am having a bit of an issue with 3D movement for an isometric game, mainly the rotation of the character. When I use the line;
var target_angle = movement_input.angle() + PI/2
The character faces the correct way when moving horizontally, but rotates backwards moving up and down (moonwalks). When I change it to;
var target_angle = movement_input.angle() - PI/2
The opposite problem, the character will face the correct direction when walking up and down, but moonwalks when moving left to right. Both ways will create problems for diagonal movement.
Feels close I just can’t get a working logic to cover it, the whole code is below;
extends CharacterBody3D
@export var base_speed := 4.0
var movement_input := Vector2.ZERO
func _physics_process(delta: float) → void:move_logic(delta)move_and_slide()
func move_logic(delta) → void:movement_input = Input.get_vector(“left”, “right”, “forward”, “backward”)
var vel_2d = Vector2(velocity.x, velocity.z)
if movement_input != Vector2.ZERO:
vel_2d += movement_input * base_speed * delta
vel_2d = vel_2d.limit_length(base_speed)
velocity.x = vel_2d.x
velocity.z = vel_2d.y
$MonkSkin/AnimationPlayer.current_animation = 'Walk'
var target_angle = movement_input.angle() + PI/2
$MonkSkin.rotation.y = rotate_toward($MonkSkin.rotation.y, target_angle, 6.0 * delta)
var targetdeg = rad_to_deg(target_angle)
print(targetdeg)
I did do a screen capture to show the problem but unfortunately new users cannot upload attachments. Thanks.