hurrmmm/godot/physics/billiard.gd

38 lines
912 B
GDScript3
Raw Normal View History

2023-11-11 16:12:46 -07:00
extends RigidBody3D
2023-11-11 17:24:52 -07:00
class_name Billiard
2023-11-11 18:48:23 -07:00
@export var power_min := 0.01
@export var power_max := 5.0
2023-11-11 17:24:52 -07:00
var can_hit = true
2023-11-11 22:38:31 -07:00
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)
func frame_inc(frame: int):
can_hit_history[frame] = can_hit
2023-11-12 03:17:46 -07:00
func frames_change(_start: int, end: int):
2023-11-11 22:38:31 -07:00
can_hit = can_hit_history[end]
func frames_reset():
can_hit_history = Dictionary()
can_hit_history[0] = can_hit
2023-11-11 17:24:52 -07:00
2023-11-11 18:48:23 -07:00
func hit(impulse: Vector3, power: float):
apply_central_impulse(impulse * lerp(power_min, power_max, power))
2023-11-11 20:45:57 -07:00
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)