44 lines
856 B
GDScript
44 lines
856 B
GDScript
extends Spatial
|
|
class_name BodyPart
|
|
|
|
# Must be the direct child of a BodyBase
|
|
|
|
|
|
onready var base = get_parent()
|
|
onready var physics_shape = get_node("PartCollider")
|
|
|
|
export(int) var key
|
|
|
|
var setup_done = false
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
assert(base is BodyBase)
|
|
|
|
|
|
|
|
|
|
func _process(delta: float) -> void:
|
|
# We do this here because we want the whole tree to really be done instancing
|
|
if not setup_done:
|
|
var translation = physics_shape.global_transform.basis * physics_shape.translation
|
|
|
|
remove_child(physics_shape)
|
|
base.add_child(physics_shape)
|
|
|
|
physics_shape.translation = translation
|
|
|
|
setup_done = true
|
|
|
|
|
|
func _unhandled_input(event):
|
|
if event is InputEventKey:
|
|
if event.pressed and event.scancode == key:
|
|
action()
|
|
|
|
|
|
# Do something with the base
|
|
func action():
|
|
pass
|