Added controller activation signal
This commit is contained in:
@ -1,4 +1,6 @@
|
||||
class_name Character
|
||||
extends CharacterBody3D
|
||||
|
||||
signal controlled(Controller)
|
||||
|
||||
var controller: Controller
|
@ -3,4 +3,8 @@ extends Node
|
||||
|
||||
signal direction_changed(direction: Vector3)
|
||||
signal jumped
|
||||
signal used_skill(slot: int)
|
||||
signal used_skill(slot: int)
|
||||
|
||||
func control(character: Character):
|
||||
character.controller = self
|
||||
character.controlled.emit(self)
|
||||
|
@ -10,10 +10,13 @@ var direction: Vector3
|
||||
var gravity: float
|
||||
|
||||
func _ready():
|
||||
body = owner as Character
|
||||
body.controller.direction_changed.connect(on_direction_changed)
|
||||
body.controller.jumped.connect(jump)
|
||||
gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
|
||||
body = owner as Character
|
||||
body.controlled.connect(on_controlled)
|
||||
|
||||
func on_controlled(controller: Controller):
|
||||
controller.direction_changed.connect(on_direction_changed)
|
||||
controller.jumped.connect(jump)
|
||||
|
||||
func _physics_process(delta):
|
||||
if direction:
|
||||
|
@ -9,11 +9,14 @@ var angle: float
|
||||
|
||||
func _ready():
|
||||
assert(root, "Rotation root needs to be set")
|
||||
owner.controller.direction_changed.connect(on_direction_changed)
|
||||
(owner as Character).controlled.connect(on_controlled)
|
||||
|
||||
func _process(delta):
|
||||
root.rotation.y = Math.damp_angle(root.rotation.y, angle, rotation_speed * delta)
|
||||
|
||||
func on_controlled(controller: Controller):
|
||||
controller.direction_changed.connect(on_direction_changed)
|
||||
|
||||
func on_direction_changed(new_direction: Vector3):
|
||||
direction = new_direction
|
||||
|
||||
|
@ -7,7 +7,10 @@ var character: Character
|
||||
|
||||
func _ready():
|
||||
character = owner
|
||||
character.controller.used_skill.connect(use_skill)
|
||||
character.controlled.connect(on_controlled)
|
||||
|
||||
func on_controlled(controller: Controller):
|
||||
controller.used_skill.connect(use_skill)
|
||||
|
||||
func use_skill(slot: int):
|
||||
if slot < 0 || slot >= skills.size():
|
||||
|
Reference in New Issue
Block a user