add animation on movement
This commit is contained in:
+9
-1
@@ -118,8 +118,16 @@ func _handle_movement(delta: float) -> void:
|
|||||||
float(Input.is_key_pressed(KEY_S) or Input.is_key_pressed(KEY_DOWN)) -
|
float(Input.is_key_pressed(KEY_S) or Input.is_key_pressed(KEY_DOWN)) -
|
||||||
float(Input.is_key_pressed(KEY_W) or Input.is_key_pressed(KEY_UP))
|
float(Input.is_key_pressed(KEY_W) or Input.is_key_pressed(KEY_UP))
|
||||||
)
|
)
|
||||||
|
var is_moving: bool = abs(input_x) > 0.0 or abs(input_z) > 0.0
|
||||||
|
if is_moving:
|
||||||
|
if not anim_player.is_playing() or anim_player.current_animation != "walk":
|
||||||
|
anim_player.play("walk")
|
||||||
|
else:
|
||||||
|
if anim_player.current_animation == "walk":
|
||||||
|
anim_player.stop()
|
||||||
|
|
||||||
var cam := get_viewport().get_camera_3d()
|
var cam := get_viewport().get_camera_3d()
|
||||||
if (abs(input_x) > 0.0 or abs(input_z) > 0.0) and cam != null:
|
if is_moving and cam != null:
|
||||||
var cam_fwd := -cam.global_transform.basis.z
|
var cam_fwd := -cam.global_transform.basis.z
|
||||||
cam_fwd.y = 0.0
|
cam_fwd.y = 0.0
|
||||||
cam_fwd = cam_fwd.normalized() if cam_fwd.length() > 0.01 else Vector3(0.0, 0.0, -1.0)
|
cam_fwd = cam_fwd.normalized() if cam_fwd.length() > 0.01 else Vector3(0.0, 0.0, -1.0)
|
||||||
|
|||||||
Reference in New Issue
Block a user