- Edited
Hello,
I was trying to merge a 3D movement with a state machine tutorial together in an experimentation.
I managed to squish most of the IDE error but my player isn't moving : it respond to input relative to the camera and face it's spawn orientation once the key's released...
it does feel like the state machine work since it can change direction only in the walk state and the initial state is Idle
walk
extends BaseState
export (float) var move_speed = 60
func input(event: InputEvent) -> int:
if Input.is_action_just_pressed("jump"):
return State.Jump
return State.Null
func physics_process(delta: float) -> int:
if !player.is_on_floor():
return State.Fall
var move_direction := Vector3.ZERO
move_direction.x = Input.get_action_strength("right") - Input.get_action_strength("left")
move_direction.z = Input.get_action_strength("back") - Input.get_action_strength("forward")
move_direction = move_direction.rotated(Vector3.UP, player._spring_arm.rotation.y).normalized()
player._velocity.x = move_direction.x * move_speed
player._velocity.z = move_direction.z * move_speed
player._velocity.y -= player.gravity * delta
if player._velocity.length() > 0.2:
var look_direction = Vector2(player._velocity.z, player._velocity.x)
player.model.rotation.y = look_direction.angle()
if move_direction == Vector3.ZERO:
return State.Idle
return State.Null
func _process(_delta: float) -> void:
player._spring_arm.translation = player.translation
I'm not even sure what is happening right there, Feels like the state machine isn't working correctly but I struggle to debug it (I managed to print the states.name but it only give me the node name : state_manager).
Got the project under for anyone wanting to dig around and give feedback.
https://mega.nz/file/Uw93xTjS#syYoLmLy8JusCXQKr3yHzrzssjQ3ufuagBQ2znD0SHY