Im working with a puzzle game that involves two character. In which if i press a button, let’s say “spacebar”, I can switch from one character to another (similar from never alone).How can i do that?
An option: Put the two objects in a group, for example “Player”, and add an “active” variable to each object.
When you press space switch each instance variable, so the Player instance with “active” = 1 will become = 0 and the one with variable “active” = 0 will become active:
Conditions: Space is pressed
Trigger once
Actions: No actions
For each Player:
Conditions: No conditions
Actions: Do = 1 - Player.Variable(active) to the variable "active" of Player
The last action is a fast way to switch from 0 to 1 and from 1 to 0.
Of course one of the Player instances must start with the variable “active” = 1 and the other with “active” = 0.
Finally in other events check if the Player “active” variable is 1, this will pick the correct instance, the active one, future actions in the event modifying Player will affect the active instance only:
Conditions: Left key pressed
Variable "active" of Player is = 1
Actions: Simulate pressing Left for Player