39 lines
1.0 KiB
GDScript
39 lines
1.0 KiB
GDScript
extends RigidBody3D
|
|
class_name Billiard
|
|
|
|
@export var power_min := 0.01
|
|
@export var power_max := 5.0
|
|
@export var initial_impulse: Vector3 = Vector3(0.0, 0.0, 0.0)
|
|
|
|
var can_hit = true
|
|
var can_hit_history := Dictionary()
|
|
|
|
func _ready():
|
|
can_hit_history[0] = can_hit
|
|
|
|
TAS_System.FrameIncremented.connect(frame_inc)
|
|
TAS_System.FramesAdvanced.connect(frames_change)
|
|
TAS_System.FramesRegressed.connect(frames_change)
|
|
TAS_System.FramesReset.connect(frames_reset)
|
|
await get_tree().create_timer(.1).timeout
|
|
apply_central_impulse(initial_impulse)
|
|
|
|
func frame_inc(frame: int):
|
|
can_hit_history[frame] = can_hit
|
|
|
|
func frames_change(_start: int, end: int):
|
|
can_hit = can_hit_history[end]
|
|
|
|
func frames_reset():
|
|
can_hit_history = Dictionary()
|
|
can_hit_history[0] = can_hit
|
|
|
|
func hit(impulse: Vector3, power: float):
|
|
apply_central_impulse(impulse * lerp(power_min, power_max, power))
|
|
|
|
|
|
func _on_body_shape_entered(_body_rid, body, _body_shape_index, _local_shape_index):
|
|
if body is Billiard:
|
|
ControllerEventBus.billiard_touched_billiard.emit(self, body)
|
|
|