[RMMV] Change variable based on player outrunning or being outrun by moving event

Burgerland

Veteran
Veteran
Joined
Sep 26, 2015
Messages
320
Reaction score
86
First Language
English
Primarily Uses
N/A
At first I thought checking player and event coordinates using regions would work, but there's two problems: not enough regions and too many regions to keep track of. So here's what I want to do, but don't know how to do it:

In my game Horseventure, I have a race on a race track that the player races in, and I want the player's placing (1st place, 2nd place, etc.) to change based on when the player is ahead of the other racers (1st place), and change when other racers pass the player by (player being in 2nd place when another racer gets ahead of the player). Player's placing is a variable. Other racers are events.

I got the idea for coordinates because of a different game making engine I used for previous games. That engine had a conditional branch that let me check if the player was above, behind, or to the side of a NPC. (The engine wasn't RPGMaker)

Untitled.png
 
Last edited:

Bex

Veteran
Veteran
Joined
Aug 2, 2013
Messages
1,492
Reaction score
408
First Language
German
Primarily Uses
RMMV
Is your Race Map a straight Line? Or what shape does the Race route have? Maybe a Picture can help.
 

Burgerland

Veteran
Veteran
Joined
Sep 26, 2015
Messages
320
Reaction score
86
First Language
English
Primarily Uses
N/A
Is your Race Map a straight Line? Or what shape does the Race route have? Maybe a Picture can help.
Thank you! The race map is a circle, so player will be going in all four cardinal directions.

Untitled.png
 
Last edited:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,956
Reaction score
13,588
First Language
English
Primarily Uses
RMMV
Why do you need to track this in a variable as the race is running? Are you doing anything during the race that depends on where the player falls? Or are you just interested in who's where at the finish line?

I helped someone with something like this a little while ago, and they were doing several laps around a circular track, needing to keep track of when a player or event completed a lap, and when the first 3 completed the entire race.
 

Burgerland

Veteran
Veteran
Joined
Sep 26, 2015
Messages
320
Reaction score
86
First Language
English
Primarily Uses
N/A
Why do you need to track this in a variable as the race is running? Are you doing anything during the race that depends on where the player falls? Or are you just interested in who's where at the finish line?
I figure a variable would be easiest to change on the fly. I need to know who's where during the entire race. Like in Mario Kart when the player's placing changes based on who's ahead of who (ex: if Mario is in first and Bowser gets ahead, then Mario is now in second and Bowser is in first).

I helped someone with something like this a little while ago, and they were doing several laps around a circular track, needing to keep track of when a player or event completed a lap, and when the first 3 completed the entire race.
I remember that, and it works. But this morning I realized that the player needs to know his placing during the whole race or he's going to be guessing about if he's winning or not.
 

Bex

Veteran
Veteran
Joined
Aug 2, 2013
Messages
1,492
Reaction score
408
First Language
German
Primarily Uses
RMMV
Counting the actual moved Maptiles/Steps would be a Way to calculate distance and therfor you know which one is on 1st Place and so on.
But if your Player can run into all directions while making the race, than this simple approach is not possible.
 

Burgerland

Veteran
Veteran
Joined
Sep 26, 2015
Messages
320
Reaction score
86
First Language
English
Primarily Uses
N/A
Counting the actual moved Maptiles/Steps would be a Way to calculate distance and therfor you know which one is on 1st Place and so on.
But if your Player can run into all directions while making the race, than this simple approach is not possible.
Now I see why you asked about the track's shape. And this is why I thought up the whole region and coordinates thing before realizing it wouldn't work. I thought that if I checked the player's coordinates via regions I could get the player's placing, but there's not enough regions for one track, and too many regions to keep track of anyways.
 

Bex

Veteran
Veteran
Joined
Aug 2, 2013
Messages
1,492
Reaction score
408
First Language
German
Primarily Uses
RMMV
Can the Player run to the inner circle route even if he starts on the outer circle?
I ask the inner circle got the shortest distance, while far outside the distance is much longer.
 

Burgerland

Veteran
Veteran
Joined
Sep 26, 2015
Messages
320
Reaction score
86
First Language
English
Primarily Uses
N/A
Can the Player run to the inner circle route even if he starts on the outer circle?
I ask the inner circle got the shortest distance, while far outside the distance is much longer.
Yes. The player can move anywhere on the track. Unless you mean the grass in the center? Than no. Grass is an impassable tile.
 

Burgerland

Veteran
Veteran
Joined
Sep 26, 2015
Messages
320
Reaction score
86
First Language
English
Primarily Uses
N/A
I've finally figured it out! I tested it in my game and it works :) Here's what you do to have a constant display of your rank in the race (1st place, 2nd place, etc.). Pictures are below!

1. Make a variable that's the player's rank in the race
2. Make a variable that's the NPC's rank in the race; make one variable per region id
3. Add region id's to your race track, these will check player and NPC ranks in the race
4. Make a switch for each region id, they will determine if the region has been touched or not

5. Make a parallel process event (cannot be a page on an existing event)
6. In said event, add the following conditional branches:
-- If player rank = 1, than show picture that displays player in 1st place
-- If player rank = 2, than show picture that displays player in 2nd place
-- Do the same for each rank in the race

7. Make a second parallel process event or page (but it cannot be a page on the player rank conditional branch event in steps 5-6)
8. In said event or page, add the following conditional branches:
-- If NPC has touched region id 1, than:
---- If the switch is off, than:
----- If the NPC's rank is less than the total number of ranks, than add one to the NPC rank variable for region 1
9. Do step 8 for each region id for each NPC
10. In the same event or page, add the following conditional branches:
-- If player has touched region id 1, than:
--- Turn on the switch and:
--- If NPC's rank is 0, than set the player's rank variable to 1; if NPC's rank is 1, than set the player's variable to 2, etc.
11. In the same event or page, when player crosses the finish/start line, than turn switches and variables off

Capture.PNG
 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
527
Reaction score
231
First Language
English
Primarily Uses
RMMV
If I needed something like this I probably would have done something with converting the coordinates to circular coordinates and tracking lap number for each player, but I see you came up with quite an interesting solution of your own.
 

Burgerland

Veteran
Veteran
Joined
Sep 26, 2015
Messages
320
Reaction score
86
First Language
English
Primarily Uses
N/A
If I needed something like this I probably would have done something with converting the coordinates to circular coordinates and tracking lap number for each player, but I see you came up with quite an interesting solution of your own.
What are circular coordinates?
 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
527
Reaction score
231
First Language
English
Primarily Uses
RMMV
They're a different way of measuring position that uses a distance and radius rather than an x and y value. You can think of them as a two-dimensional analog to longitude, latitude, and altitude - you measure the direct distance to the origin, and the angle between that line and one of the axes (most commonly either the positive x axis or the positive y axis). You can convert between x-y coordinates and circular coordinates with basic trigonometry.
 

Burgerland

Veteran
Veteran
Joined
Sep 26, 2015
Messages
320
Reaction score
86
First Language
English
Primarily Uses
N/A
They're a different way of measuring position that uses a distance and radius rather than an x and y value. You can think of them as a two-dimensional analog to longitude, latitude, and altitude - you measure the direct distance to the origin, and the angle between that line and one of the axes (most commonly either the positive x axis or the positive y axis). You can convert between x-y coordinates and circular coordinates with basic trigonometry.
Could you PM me how to use circular coordinates in RMMV? I've tried googling it but found nothing.
 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
527
Reaction score
231
First Language
English
Primarily Uses
RMMV
Well, I haven't actually tried it in RMMV, so there could be some issues (in particular, what does "distance" actually mean on a tile grid?), but... it's a general math concept so there's likely lots of information on how to use them.

In the specific case of a circular race track though, you could probably ignore the distance issue, because all you need is the angle. That's the information that tells you who's ahead and who's behind. In RMMV code (a Conditional Branch script call) with the player and a reference event, I suppose that would translate to something along these lines (note: this code is totally untested):

JavaScript:
((p, e) => Math.atan2(p.y, p.x) < Math.atan2(e.y, e.x))($gamePlayer, this.character(3))
That would compare the angular position of the player and event 3. There are doubtless a lot of issues with that code, mind you. For starters, the centre of the circle for that comparison is the top left corner of the map, while I assume the centre of the map would be what you need, so some additional math would be required to obtain that. Then there's the fact that it returns an angle, that is a value between (if I recall correctly) -π and π, meaning that there's a point where once you cross it you'll suddenly be considered behind instead of ahead, necessitating a lap number tracking to supplement it; and also I'm not quite sure where 0 would be so it would need to be tested. Oh, and I may have gotten the direction of the comparison wrong - perhaps it should be > rather than <. That one depends on whether the race is in a clockwise or counter-clockwise direction, but I'm also not sure which means which off the top of my head.

If you still want me to help you work through these issues in PM, then I'm open to giving some tips; just keep in mind that I may be slow to respond sometimes.

I don't think there's anything wrong with the solution you came up with, to be clear - using regions to track the player's progress through the track seems like a legitimate solution, and if it works well, there's no need to replace it with something else that may or may not actually work very well. But it's up to you.
 

Burgerland

Veteran
Veteran
Joined
Sep 26, 2015
Messages
320
Reaction score
86
First Language
English
Primarily Uses
N/A
Well, I haven't actually tried it in RMMV, so there could be some issues (in particular, what does "distance" actually mean on a tile grid?), but... it's a general math concept so there's likely lots of information on how to use them.

In the specific case of a circular race track though, you could probably ignore the distance issue, because all you need is the angle. That's the information that tells you who's ahead and who's behind. In RMMV code (a Conditional Branch script call) with the player and a reference event, I suppose that would translate to something along these lines (note: this code is totally untested):

JavaScript:
((p, e) => Math.atan2(p.y, p.x) < Math.atan2(e.y, e.x))($gamePlayer, this.character(3))
That would compare the angular position of the player and event 3. There are doubtless a lot of issues with that code, mind you. For starters, the centre of the circle for that comparison is the top left corner of the map, while I assume the centre of the map would be what you need, so some additional math would be required to obtain that. Then there's the fact that it returns an angle, that is a value between (if I recall correctly) -π and π, meaning that there's a point where once you cross it you'll suddenly be considered behind instead of ahead, necessitating a lap number tracking to supplement it; and also I'm not quite sure where 0 would be so it would need to be tested. Oh, and I may have gotten the direction of the comparison wrong - perhaps it should be > rather than <. That one depends on whether the race is in a clockwise or counter-clockwise direction, but I'm also not sure which means which off the top of my head.

If you still want me to help you work through these issues in PM, then I'm open to giving some tips; just keep in mind that I may be slow to respond sometimes.

I don't think there's anything wrong with the solution you came up with, to be clear - using regions to track the player's progress through the track seems like a legitimate solution, and if it works well, there's no need to replace it with something else that may or may not actually work very well. But it's up to you.
Thank you! I was just curious if it could work in RMMV. Maybe you could do a tutorial thread on the subject? It'd be interesting to see what else RMMV can do, since it can already do 3D. I'm going to stick with what I've come up with; I don't know much about trig :p
 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
527
Reaction score
231
First Language
English
Primarily Uses
RMMV
Thank you! I was just curious if it could work in RMMV. Maybe you could do a tutorial thread on the subject? It'd be interesting to see what else RMMV can do, since it can already do 3D. I'm going to stick with what I've come up with; I don't know much about trig :p
Not sure if I have the time for a full tutorial thread, but I'll think about it. :)
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Posts

Latest Profile Posts

Stream will be live shortly with some Darkest Dungeon! Feel free to drop by!
Ksi
Streaming the Trials of RPG Maker MZ event games! Come join us to see what you can do with ONLY the RPGMakerMZ engine (no plugins included!)
Just a ordinary seller.
I never saw any jrpg story about the chosen one and his companions done very straight to follow all basic jrpg tropes.

Forum statistics

Threads
103,384
Messages
999,194
Members
134,901
Latest member
rustiic
Top