Working on the Untitled Racing Game portion of Party Call I can finally choose a random character to be the player. Just had to adjust the Camera, note: reparenting does not move it, resulting in the wsame camera following other characters.
func initialize(entity : Node3D, script : Script, path : Array = []):
# https://forum.godotengine.org/t/scripts-wont-work-after-being-attached-to-node-via-code/9633
entity.set_script(script)
if entity.has_method('_ready'):
entity._ready() # this is required to set non-exported default values
entity.set_process(true) # if you have processing logic
entity.set_physics_process(true) # if you have physics logic
if entity.has_method('_input'):
entity.set_process_input(true)
if entity.has_method('step'):
entity.get_node('Timer').connect('timeout', entity.step)
if len(path) > 0:
entity.PATH = path
func _ready():
pick = randi_range(0, 3)
if pick == 0:
initialize(%Rogue, PLAYER)
PICK = get_node('Rogue')
CAM.reparent(PICK)
CAM.position.x = 0
else:
initialize(%Rogue, COUNTER, [Vector3(46, 0, 54), Vector3(-46, 0, 54), Vector3(-46, 0, 0)]) #PLAYER
if pick == 1:
initialize(%Mage, PLAYER)
PICK = get_node('Mage')
CAM.reparent(PICK)
CAM.position.x = 0
else:
initialize(%Mage, COUNTER, [Vector3(48, 0, -58), Vector3(-48, 0, -58), Vector3(-48, 0, 0)])
if pick == 2:
initialize(%Knight, PLAYER)
PICK = get_node('Knight')
CAM.reparent(PICK)
CAM.position.x = 0
else:
initialize(%Knight, COUNTER, [Vector3(46, 0, -56), Vector3(-44, 0, -56), Vector3(-44, 0, 0)])
if pick == 3:
initialize(%Barbarian, PLAYER)
PICK = get_node('Barbarian')
CAM.reparent(PICK)
CAM.position.x = 0
else:
initialize(%Barbarian, COUNTER, [Vector3(42, 0, 56), Vector3(-42, 0, 56), Vector3(-42, 0, 0)])
This brought other isssues since the Camera moved but a simple onready var CAM = get_node('...')
solved it. It is very easy to lose now.