ajout de la touche pour changer entre run et walk

This commit is contained in:
deed 2023-10-08 20:54:58 +02:00
parent d08dd9891b
commit 3efdcc3a03

View file

@ -1,9 +1,10 @@
extends CharacterBody3D extends CharacterBody3D
const speed = 5.0 const speed_walk = 1.0
const speed_run = 4.0
const JUMP_VELOCITY = 4.5 const JUMP_VELOCITY = 4.5
const lent = 0.05 const lent = 0.05
var action_speed= false
@onready var animation_player = $visuals/raference/AnimationPlayer @onready var animation_player = $visuals/raference/AnimationPlayer
@onready var visuals = $visuals @onready var visuals = $visuals
@ -26,13 +27,18 @@ func _physics_process(delta):
visuals.rotation += perso_y * lent visuals.rotation += perso_y * lent
if Input.is_action_pressed("ui_down"): if Input.is_action_pressed("ui_down"):
direction -= perso_z direction -= perso_z
animation_player.play_backwards( "raference_march")
if Input.is_action_just_pressed("ui_change_speed"):
action_speed = !action_speed
if Input.is_action_pressed("ui_up"): if Input.is_action_pressed("ui_up"):
if action_speed:
direction += perso_z * speed_run
animation_player.play( "raference_run")
else:
direction += perso_z direction += perso_z
animation_player.play( "raference_march") animation_player.play( "raference_march")
if Input.is_action_pressed("ui_run"): if Input.is_action_pressed("ui_camera"):
direction += perso_z * speed $camerapivot/Camera3D.global_transform = perso.direction
animation_player.play( "raference_run")
if direction.x == 0 and direction.z == 0: if direction.x == 0 and direction.z == 0:
animation_player.play( "raference_idle") animation_player.play( "raference_idle")
if Input.is_action_pressed("ui_cancel"): if Input.is_action_pressed("ui_cancel"):
@ -42,8 +48,8 @@ func _physics_process(delta):
#direction = direction.normalized() #direction = direction.normalized()
#perso_y.look_at(position + direction, Vector3.UP) #perso_y.look_at(position + direction, Vector3.UP)
target_velocity.x = direction.x * speed target_velocity.x = direction.x * speed_walk
target_velocity.z = direction.z * speed target_velocity.z = direction.z * speed_walk
if is_on_floor() and Input.is_action_just_pressed("ui_jump"): if is_on_floor() and Input.is_action_just_pressed("ui_jump"):
target_velocity.y = jump_force target_velocity.y = jump_force