generated from krampus/template-godot4
	
		
			
				
	
	
		
			38 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			GDScript
		
	
	
	
	
	
			
		
		
	
	
			38 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			GDScript
		
	
	
	
	
	
| class_name CharacterController extends Node3D
 | |
| ## Controller class for character animations
 | |
| 
 | |
| @onready var animation_tree: AnimationTree = $AnimationTree
 | |
| @onready
 | |
| var animation_state: AnimationNodeStateMachinePlayback = animation_tree["parameters/playback"]
 | |
| 
 | |
| @onready var right_hand_grip: Node3D = %RightHandGrip
 | |
| @onready var eye_animation: AnimationPlayer = %EyeAnimation
 | |
| 
 | |
| 
 | |
| ## Snap the given node to the character's right hand grip.
 | |
| ## Anything currently held in the right hand will be freed.
 | |
| ## If `node` is null, the character's right hand grip will just be cleared.
 | |
| func hold_right(node: Node3D = null) -> void:
 | |
| 	for c: Node in right_hand_grip.get_children():
 | |
| 		c.queue_free()
 | |
| 
 | |
| 	if node:
 | |
| 		right_hand_grip.add_child(node)
 | |
| 		node.transform = Transform3D.IDENTITY
 | |
| 
 | |
| 
 | |
| func reset() -> void:
 | |
| 	animation_state.start("stand_to_idle")
 | |
| 
 | |
| 
 | |
| func start_upswing() -> void:
 | |
| 	animation_state.travel("upswing")
 | |
| 
 | |
| 
 | |
| func downswing() -> void:
 | |
| 	animation_state.travel("downswing")
 | |
| 
 | |
| 
 | |
| func _on_blink_timer_timeout() -> void:
 | |
| 	eye_animation.play("blink")
 |