I'm trying to change the below code into twin stick movement, where WASD moves left and right, up and down, and the rotation of the sprite is based on where the cursor is.
extends CharacterBody3D
# How fast the player moves in meters per second.
@export var speed = 14
# The downward acceleration when in the air, in meters per second squared.
@export var fall_acceleration = 75
@export var jump_impulse = 20
@onready var animation_tree = $AnimationTree
@onready var state_machine = animation_tree.get('parameters/playback')
func _ready():
animation_tree.active = true
func _physics_process(delta):
var direction = Vector3.ZERO
if Input.is_action_pressed("ui_right"):
direction.x += 1
if Input.is_action_pressed("ui_left"):
direction.x -= 1
if Input.is_action_pressed("ui_down"):
direction.z += 1
if Input.is_action_pressed("ui_up"):
direction.z -= 1
if direction != Vector3.ZERO:
animation_tree.set('parameters/Idle/blend_position', direction)
direction = direction.normalized()
velocity.x = direction.x * speed
velocity.z = direction.z * speed
velocity.y -= fall_acceleration * delta
move_and_slide()
if is_on_floor() or is_on_ceiling():
velocity.y = 0.0
if is_on_floor() and Input.is_action_just_pressed("jump"):
velocity.y += jump_impulse
imgur link of what it look like now. Any help is appreciated, thanks!