0 Favourites

# See which player is in lead?

• 10 posts
• I have a racing game, with 3 opponents which race around the track, but how do i tell which one is in the lead?

• Are the opponents separate sprites, or are they just clones of the same sprite?

If they are separate sprites you could make a variable Opponent1X or Opponent1Y (depending on if the direction is vertical or horizontal) and create an event to declare the variable as Opponent.X or Opponent.Y. Make another even that compares your location to theirs like so: Player.X < Opponent1X = you are behind the opponent or Player.Y < Opponent1Y = you are behind the enemy. You can make a boolean variable (either instanced or global) that determines that you are behind the enemy.

• clones, but i gave them each a local variable so they have a name.

• Im not sure if the players x is greater than opponents x will work, because then at some points on the track the x will be greater than the opponents event when the player is not in the lead, same for y

• What I am thinking is probably different than what you have. I'm at work atm so if someone answers you than great if not i'll look at it when I get home.

• How about using invisible sprites as waypoints and use individual instance variables for the cars to keep a count of laps and waypoints.

• you should probably combine some checks, first of all you keep track of laps, if lap greater then , is ahead, then keep track of wich waypoint it crossed, if waypoint is > is ahead, en then maybe distance to next waypoint is smaller then,

distance to next 50px is ahead of distance 60px

edit: you better use distance is greater then and use the waypoints that already crossed

• vtrix, thanks for your advice, but im having trouble understanding how to do this, I have a finish line, which im using to count the laps of my player, Are you saying i should do the same but for the opponents? But if so there just copy's of each other not individual sprites.. Haave you downloaded the capx? maybe you could show me?

• ## Buy Construct 3

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

Construct 3 users don't see these ads
• i didnt sayed it was easy, this would take me to long to 'show you' you have multiple npc's these have to be compaired to eachother and to the player, there is still much to do, like surrounding borders so player/npc cant go way offroad, you are however already counting the waypoints per npc

as for the npc crossing finish,

for each npc

on collision with startline

npc.name = Mcdonalds    | add 1 to npc.currentlap

• I added all the Bounding boxes ect.

• 10 posts