khanat-client/scenes/player/creature_root.gd

92 lines
2.1 KiB
GDScript

extends KinematicBody
class_name CreatureRoot
var animation_walk = "march"
var animation_run = "run"
var animation_scan_loop = "scanne_loop"
var animation_teleport_loop = "teleporte_loop"
var rotation_speed_factor = 0.01
var move_speed = 2.5
var run_speed = 5.0
var max_speed = 12.0
export var gravity = -9.0
var animation_object:AnimationPlayer = null
var orientation = 0.0
var direction = Vector3.ZERO
var velocity = Vector3.ZERO
var rotatex = 0.0
var move_run: bool = false
var move_toggle_run: bool = false
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():
if i.get_name() == "AnimationPlayer":
animation_object = i
return true
else:
ret = search_animation(i)
if ret == true:
return ret
return false
func update_blend_shapes( obj , param):
#blend_shapes = {}
update_blend_shapes_step(obj, param, "")
pass
func update_blend_shapes_step( obj, param, father = "" ):
for i in obj.get_children():
var root = father + str(i.name) + "."
if i is MeshInstance:
for key in i.get_property_list():
if key.name.substr(0, 13) == "blend_shapes/":
var blend = key.name.substr(13)
if param.has(blend):
i.set( "blend_shapes/"+blend, param[blend] )
update_blend_shapes_step( i, param, root)
func get_animation_idle():
# Possibility to have a multiple idle animation and select one
return "idle"
# Called when the node enters the scene tree for the first time.
func _ready():
current_action = ACTION.idle
search_animation( self )
launch_animation_idle()
func launch_animation_idle():
var idlename = self.get_animation_idle()
animation_object.play( idlename )
animation_object.connect("animation_finished", self, "_on_animation_finished")
func _on_animation_finished(anim_name):
Config.msg_debug( "{" + self.name + "} Animation finished:" + anim_name)
animation_object.play( anim_name )
func update_animation(action, anim_name):
# Change animation if we need
if current_action != action:
current_action = action
animation_object.play( anim_name )