2020-02-01 11:09:06 +01:00

43 lines
815 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:
if not setup_done:
var translation = physics_shape.to_global(physics_shape.translation)
physics_shape.translation = Vector3.ZERO
remove_child(physics_shape)
base.add_child(physics_shape)
physics_shape.global_transform.origin = 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