ading animation on move or idle

This commit is contained in:
AleaJactaEst 2021-09-04 16:33:34 +02:00
parent f619971496
commit 520ac8f36c

View file

@ -8,6 +8,16 @@ var velocity: = Vector3.ZERO
var rotatex = 0.0
export var gravity = -9.0
enum ACTION {
idle,
walk,
run,
scan,
teleport,
}
var current_action = ACTION.idle
func search_animation( obj ) -> bool:
var ret:bool = false
for i in obj.get_children():
@ -35,6 +45,7 @@ func _ready():
# search_animation($character)
# Globals.player['blend_shape']
update_blend_shapes($creature, Globals.player['blend_shape'])
current_action = ACTION.idle
var idlename = "idle"
if $creature.has_method("get_animation_idle"):
idlename = $creature.get_animation_idle()
@ -43,6 +54,13 @@ func _ready():
animation_object.connect("animation_finished", self, "_on_AnimationPlayer_animation_finished")
func update_animation(action, anim_name):
# Change animation if we need
if current_action != action:
current_action = action
animation_object.play( anim_name )
func _on_AnimationPlayer_animation_finished(anim_name):
Config.msg_debug("Animation finished:" + anim_name)
animation_object.play( anim_name )
@ -113,6 +131,26 @@ func _process( delta ):
var pos : Vector3 = $creature.get_global_transform().origin
Config.msg_info("pos X:" + str(pos.x) + " Y:" + str(pos.y) + " Z:" + str(pos.z))
if input_direction:
if not input_direction.z == 0.0:
#if self.is_sprinting():
# $model/ra/model/AnimationPlayer.play( "run" )
#else:
# $model/ra/model/AnimationPlayer.play( "walk" )
update_animation( ACTION.walk, $creature.animation_walk )
pass
elif input_direction.x > 0.0:
# $model/ra/model/AnimationPlayer.play( "strafe_right" )
update_animation( ACTION.idle, $creature.get_animation_idle() )
elif input_direction.x < 0.0:
# $model/ra/model/AnimationPlayer.play( "strafe_left" )
update_animation( ACTION.idle, $creature.get_animation_idle() )
else:
update_animation( ACTION.idle, $creature.get_animation_idle() )
else:
# $model/ra/model/AnimationPlayer.play( "idle" )
update_animation( ACTION.idle, $creature.get_animation_idle() )
pass
func calculate_velocity(
velocity_current: Vector3,