89 lines
2.8 KiB
GDScript
89 lines
2.8 KiB
GDScript
|
|
extends Node3D
|
||
|
|
var game
|
||
|
|
var animator: AnimationPlayer
|
||
|
|
var walking=false
|
||
|
|
var striking=false
|
||
|
|
var clips={}
|
||
|
|
var gait=preload("res://catwalk.gd").new()
|
||
|
|
var animation_pose: Array[Transform3D]=[]
|
||
|
|
var skeleton: Skeleton3D
|
||
|
|
|
||
|
|
|
||
|
|
func _init():
|
||
|
|
name="ApprovedSuccubus"
|
||
|
|
set_meta("approved_model","succubus_v01")
|
||
|
|
set_meta("wardrobe_revision","corset_thigh_boots_v02")
|
||
|
|
var model=preload("res://art/succubus/succubus_v02.glb").instantiate()
|
||
|
|
add_child(model)
|
||
|
|
model.scale=Vector3.ONE*1.20
|
||
|
|
for node in model.find_children("*","AnimationPlayer",true,false):
|
||
|
|
animator=node
|
||
|
|
break
|
||
|
|
assert(animator!=null)
|
||
|
|
for name in animator.get_animation_list():
|
||
|
|
for clip in ["Idle","Walk","Whip"]:
|
||
|
|
if String(name).ends_with(clip):clips[clip]=name
|
||
|
|
for clip in ["Idle","Walk"]:
|
||
|
|
if clips.has(clip):animator.get_animation(clips[clip]).loop_mode=Animation.LOOP_LINEAR
|
||
|
|
if clips.has("Whip"):animator.get_animation(clips["Whip"]).loop_mode=Animation.LOOP_NONE
|
||
|
|
animator.callback_mode_process=AnimationMixer.ANIMATION_CALLBACK_MODE_PROCESS_MANUAL
|
||
|
|
animator.animation_finished.connect(_finished)
|
||
|
|
rotation.y=.58
|
||
|
|
|
||
|
|
func configure(g):
|
||
|
|
game=g
|
||
|
|
animator.play(clips["Idle"]);animator.advance(0)
|
||
|
|
gait.setup(self);skeleton=gait.skeleton
|
||
|
|
remember_animation_pose()
|
||
|
|
refresh()
|
||
|
|
|
||
|
|
func set_walking(value):
|
||
|
|
if walking==value:return
|
||
|
|
walking=value # Locomotion is procedural; the Idle base clip must not restart.
|
||
|
|
|
||
|
|
func strike(duration):
|
||
|
|
if not clips.has("Whip"):return
|
||
|
|
restore_animation_pose()
|
||
|
|
striking=true
|
||
|
|
var speed=animator.get_animation(clips["Whip"]).length/maxf(.20,duration)
|
||
|
|
animator.play(clips["Whip"],.035,speed)
|
||
|
|
animator.seek(0,true)
|
||
|
|
remember_animation_pose()
|
||
|
|
|
||
|
|
func refresh():
|
||
|
|
restore_animation_pose()
|
||
|
|
var key="Idle" # Grounded gait supplies the lower body and runway motion.
|
||
|
|
if clips.has(key):animator.play(clips[key],.12,1.0)
|
||
|
|
|
||
|
|
func _finished(name):
|
||
|
|
if clips.has("Whip") and name==clips["Whip"]:
|
||
|
|
striking=false
|
||
|
|
refresh()
|
||
|
|
|
||
|
|
func reset_gait():
|
||
|
|
if gait.initialized:gait.reset()
|
||
|
|
|
||
|
|
func _process(delta):
|
||
|
|
if game and game.paused:return
|
||
|
|
var dt=minf(delta,.05)
|
||
|
|
restore_animation_pose()
|
||
|
|
animator.advance(dt)
|
||
|
|
remember_animation_pose()
|
||
|
|
gait.update(dt)
|
||
|
|
|
||
|
|
func remember_animation_pose():
|
||
|
|
if not is_instance_valid(skeleton):return
|
||
|
|
animation_pose.resize(skeleton.get_bone_count())
|
||
|
|
for i in range(animation_pose.size()):animation_pose[i]=skeleton.get_bone_pose(i)
|
||
|
|
|
||
|
|
func restore_animation_pose():
|
||
|
|
if not is_instance_valid(skeleton):return
|
||
|
|
# Godot can skip writing unchanged animation tracks. Remove the previous
|
||
|
|
# procedural offsets before sampling or starting a blend to avoid feedback.
|
||
|
|
for i in range(animation_pose.size()):
|
||
|
|
var pose=animation_pose[i]
|
||
|
|
skeleton.set_bone_pose_position(i,pose.origin)
|
||
|
|
skeleton.set_bone_pose_rotation(i,pose.basis.get_rotation_quaternion())
|
||
|
|
skeleton.set_bone_pose_scale(i,pose.basis.get_scale())
|
||
|
|
skeleton.force_update_all_bone_transforms()
|