khanat-client/scenes/player/playerB.gd

127 lines
3.8 KiB
GDScript3
Raw Normal View History

2021-09-04 10:49:56 +00:00
extends Spatial
var animation_object:AnimationPlayer = null
var rotation_speed_factor = 0.01
var orientation = 0.0
var direction = Vector3.ZERO
export var gravity = -9.0
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
# Called when the node enters the scene tree for the first time.
func _ready():
match Globals.player['Race']:
"arche":
self.change_creature( "res://scenes/player/creature_raference.tscn" )
"isidor":
self.change_creature( "res://scenes/player/creature_raference.tscn" )
"raference":
self.change_creature( "res://scenes/player/creature_raference.tscn" )
_:
self.change_creature( "res://scenes/player/creature_raference.tscn" )
# search_animation($character)
# Globals.player['blend_shape']
update_blend_shapes($creature, Globals.player['blend_shape'])
var idlename = "idle"
if $creature.has_method("get_animation_idle"):
idlename = $creature.get_animation_idle()
self.rotation_speed_factor = $creature.rotation_speed_factor
animation_object.play( idlename )
animation_object.connect("animation_finished", self, "_on_AnimationPlayer_animation_finished")
func _on_AnimationPlayer_animation_finished(anim_name):
Config.msg_debug("Animation finished:" + anim_name)
animation_object.play( anim_name )
func change_creature( new_model_path ):
if $creature:
var old_model = $creature
self.remove_child( old_model )
old_model.queue_free()
self.animation_object = null
var new_model = load( new_model_path )
if new_model:
new_model = new_model.instance()
new_model.name = "creature"
self.add_child( new_model )
#new_model.connect( "animation_finished", self, "_on_creature_animation_finished" )
# new_model.duplicate_meshes()
search_animation( new_model )
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)
static func get_input_direction() -> Vector3:
return Vector3(
Input.get_action_strength("move_strafe_right") - Input.get_action_strength("move_strafe_left"),
0,
Input.get_action_strength("move_backward") - Input.get_action_strength("move_forward")
)
func _process( delta ):
Config.msg_info( Input.get_action_strength("move_backward") )
Config.msg_info( Input.get_action_strength("move_forward") )
# $character.direction = self.get_input_direction()
#self.direction = self.get_input_direction()
self.direction = self.get_input_direction()
self.rotate_y( self.rotation_speed_factor * self.orientation )
func calculate_velocity(
velocity_current: Vector3,
move_direction: Vector3,
delta: float
) -> Vector3:
var velocity_new = Vector3.ZERO
velocity_new = move_direction
velocity_new *= $creature.move_speed
if velocity_new.length() > $creature.max_speed:
velocity_new = velocity_new.normalized() * $creature.max_speed
velocity_new.y = velocity_current.y + gravity * delta
return velocity_new
func _input( event ):
# Config.msg_debug(str(event))
self.direction = self.get_input_direction()
if not Input.is_key_pressed( KEY_SHIFT ):
self.orientation = (Input.get_action_strength("move_turn_left") - Input.get_action_strength("move_turn_right"))
else:
self.orientation = 0.0
if event is InputEventMouseMotion and Input.is_mouse_button_pressed( 2 ):
if $creature:
self.rotate_y( event.relative.x *0.01 )