How do I Switch active player?

0 favourites
  • 6 posts
From the Asset Store
Basic Rounded Vector Geometry Player Design with Glow for 3 player games
  • Hello !

    I'm trying to create a small soccer game to learn more about construct.

    I created a sprite for the player, and have coded some basic movements and actions with him and the ball.

    Now I'm trying to have the active player (the player answering to the controls) switch everytime the ball is passed to another player sprite.

    Note that all player sprites are created on runtime from the same object, and thanks to a function, hey each recieve a unique ID variable on creation ("player00", "player01", etc.).

    So on startup, I can differentiate which player is which (and for now, all the controls are attributed to the first player sprite created). How can I use that knowledge to create some kind of "active player" condition and have my coded behaviors separated between the active player and the AI ?

    Thanks for your help !

  • Depends on how you are making that player active, you could for example set the player to active on ball collision, 'active' being a variable on the player. Then you have an event for whichever player is active, the controls are enabled, else for the others the controls are disabled. For the AI you could have another variable to mark them as AI or it might be easier to use a second object for this.

  • Yes okay, I see what you're proposing. It's what I have in mind, but I don't see how to implement it.

    Since all players are instances of the same object (created at runtime), I don't understand how having a variable on that object would work.

    Like, if it is a boolean ("activeplayer"), it will be set True at the start of the layout for one of the instance (the one the player controls at the beginning of the game) ; and then, as soon as the player passes the ball to another instance, how would the boolean would have to be set up so it switches when the collision happens ? It can't be switched off while the ball is being passed, as the player will want to still control his character until the ball reaches another instance of the player...

    I feel like I'm missing/misundertsanding something very basic for it to work...

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • This is a little confusing only because you have to pick 2 of the same object and apply actions and you need a kind of workaround. For example if object A passed to object B you could say set A inactive and set B active, but because they are the same object and you need to pick both the active and inactive player then the picking is a little more difficult.

    My approach would be ball on collision with player (where player is set to inactive), grab this instance ID so lets say it is player01. Then you set all players to inactive, then you use system pick all players to open them all up to being picked again (this is required as when you did the initial on collision event you narrowed the player to one instance), then finally you pick player where id is 01 and set them to active! This is all in one event done with sub events.

  • global variable check. when the ball has collision with a player, set the global variable to player.uid (unique identity)

    then have a

    player.uid =uid(global). enable 8d and scroll too.

    then

    for each player, is uid (not equal) to global variable.

    then add disable 8d or scroll to the inactive ones

    should be a simple solution, might need an every tick in there

    hope that helps!

    its the ai thats a pain

  • Thanks, I'll try that !! Seems simple enough, indeed !

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)