Hey!
I’ve been making a relatively complex game recently which involves switching between players. These players each have events linked to them which makes a single camera follow them. As of now, my code is along these lines:
If global variable ‘characterused’ = ‘player’ Move camera to object ‘player’ with a force of 280 etc…
If global variable ‘characterused’ = ‘greenplayer’ Move the camera to object ‘greenplayer’ with a force of 280 etc…
I was wondering if it would be possible instead to do this:
When a new player is selected, set a global variable, which could be called ‘characterused’ to that player’s name.
Then have a constant event which moves the camera to object GlobalVariableString(characterused)
That way, it would be much easier to implement more characters without having to write a lot of code.
Thanks for your help,
Blooper
Could you please re-create this in GD and screenshot it please? I’m having trouble setting up those events
I can’t seem to add multiple events to the ‘while’ block.
Sorry guys, I’m still having trouble with this one.
I dunno, maybe if I fully explain my game to you, we can make more progress
Let’s say I have 2 characters:
Player
GreenPlayer
I want to be able to switch between them in-game and control them individually with the camera following the one that I’m currently using.
The code I have is as follows:
No conditions Do =GlobalVariableString(characternumber) to the text of characternumber
Global variable CharacterNumber is =0 Do ="player" to the text of global variable CharacterUsed
The text of the global variable CharacterUsed is ="player"
No conditions Rotate player to MouseX();MouseY()
w key is pressed Do -0.6 to Y position of Player
Do =1 to global variable Moving
Then the same but for A/S/D
Now I have the same for ‘GreenPlayer’ but it’s when the Global Variable CharacterNumber is =1
I have an invisible object Called ‘PlayerTracer’ which follows whichever character is being used. The camera is centered around ‘PlayerTracer’, which moves towards the player in use.
What I want to do is have a system where I don’t have to keep replicating code for each player I have (which will be around 6 per level).
That’s why I wanted to know if it was possible to center the camera around a player whose name is stored in a variable instead of the way I have it now.
If both players are the same object (from object Player you create two instances “Player”) it should be easy…
-Create a variable “ID” for each Player, ID = 1 for Player 1 and “ID” = 2 for Player 2
-Create a scene variable “ActualPlayer” = 1
Event to change players, for example:
"E" key is pressed:
........Action: variable "checkNext" = 1
........If variable "ActualPlayer" = 2:
................Action: variable "ActualPlayer" = 1
................Action: variable "checkNext" = 0
........If variable "ActualPlayer" = 1 and variable "checkNext" = 1:
................Action: variable "ActualPlayer" = 2
or something like this (variable “checkNext” to know if the next sub-event should be executed)
Events related to active Player needs the condition: