How does one change the current controlled KinematicBody2d

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By phil1234


everything was working fine until I added another kinematicBody2D

the later was used as the default player

how do I select the default player kinematicBody2D

  • on startup
  • programmatically during the game ?


:bust_in_silhouette: Reply From: Magso

Godot doesn’t have a default player or anything like UE4’s game mode options (if that’s the kind of thing you’re looking for).

You will need to either need the player script on both and use a bool that allows control or a separate script e.g. a singleton aka autoload script that holds all the references of existing players in an array and selects the player using an int.

well it obviously does since it’s choosing between one the two kinematics…at least around the camera used by default

how do I set the wanted camera to be used ?

phil1234 | 2021-05-17 20:04

also if there are many cameras,

how do I address them programmatically ?

they are just called Camera2D, I would need some identifier to use at programming time

can I get an array of available cameras and a tag to identify them somehow in the script ?

phil1234 | 2021-05-17 20:10

That’s the current property on the camera, not a selected player option. If another Camera has current set to true it overrides the last camera being used.

Magso | 2021-05-17 20:11

Yes, in Godot tags are called groups and get_tree().get_nodes_in_group("group/tag name") returns an array in the scene hierarchy order.

Magso | 2021-05-17 20:13

It’s also worth noting that Godot doesn’t use a GUID system until runtime which means references are made in the editor and scripts by NodePaths that need to be passed through get_node() at runtime to return the actual node.

Magso | 2021-05-17 20:18

is there a way to have a startup script (global to the game/level) so I can setup things ?

phil1234 | 2021-05-17 20:18

Yep, go to Project > Project Settings > Autoload tab. In Path choose the directory of a script and Node Name is the reference name that can be used from any other script.

Magso | 2021-05-17 20:26

ok I found how to use singleton and project settings
thanks for your help guys

phil1234 | 2021-05-17 20:33