How do I make a positioning system in a race game?

Just started using Construct 2? Post your questions here

Post » Sat Oct 25, 2014 11:20 am

I've attempting to create a race game using @SeriouslyCrunchy 's car AI tutorial.

But my game needs a position indicator which shows the current position of the player.

How do I implement the feature, do I have to use mathematical functions or using waypoints?

Also, is it possible to make a position indicator which is similar to Mario Kart?
SONAR Gamer's Club Discord |
Twitter | Facebook | Instagram

If you play Puyo Puyo games, you can meet me at the Puyo Puyo English Community Discord: https://discord.gg/0k41S8ARwvY2iTIQ
B
111
S
27
G
11
Posts: 702
Reputation: 13,223


Post » Sun Oct 26, 2014 3:15 am

@Lordshiva1948 - Thanks, I'll use that technique for indicating cars on the track.

But what I meant is a ranking system. Which if the player is in the 1st position or else.
SONAR Gamer's Club Discord |
Twitter | Facebook | Instagram

If you play Puyo Puyo games, you can meet me at the Puyo Puyo English Community Discord: https://discord.gg/0k41S8ARwvY2iTIQ
B
111
S
27
G
11
Posts: 702
Reputation: 13,223

Post » Mon Oct 27, 2014 12:27 am

Keeping track of what waypoint the car is on is a way to give a very rough estimate of the rank. You can get a finer rank by also considering the perpendicular distance to the next waypoint.

So the event needed would basically look like this:

For each car ordered by waypoint*1000-perpDistToWaypoint decending
--- loopindex+1 is the rank.

If the distance between checkpoints can be more than 1000 change it to some higher value.

Ex.
https://www.dropbox.com/s/y3xhf4wp2t6kh ... .capx?dl=1
/examples26/laps.capx

The perpendicular distance is the dot product between the waypoint line and the vector from the waypoint to the player. It can actually give us negative distances so we'll put it in a abs() so it's always positive.

Player = {x, y}
waypoint_to_player = {x-way.x, y-way.y}
waypoint_line = {cos(waypoint.angle), sin(waypoint.angle)}
perp_dist =abs( waypoint_to_player dot waypoint_line )=abs( {x-way.x, y-way.y} dot {cos(waypoint.angle), sin(waypoint.angle)} )
= abs((x-way.x)*cos(waypoint.angle) + (y-way.y)*sin(waypoint.angle))
vector
Last edited by R0J0hound on Mon Mar 19, 2018 7:02 pm, edited 1 time in total.
B
100
S
38
G
134
Posts: 5,552
Reputation: 85,317

Post » Thu Oct 12, 2017 5:50 pm

Found this old thread looking for something like this, but I'm not using waypoints in my racer because the complexity of the levels. Since you have all the positions at start I'm trying to detect if something is passing me instead. Still working on it but getting there.

If you are position 1 travelling at angle 90, then if a car passes (within a certain distance), the angle between you and the car that just passed you would be within 180degree of the direction your going (infront of you). When this happens you could easily trigger an update to the current positions i suppose?

So I think detecting if something is behind or infront of you would be better and more exact?
Follow my progress on Twitter
or in this thread Archer Devlog
B
49
S
22
G
19
Posts: 1,135
Reputation: 14,812

Post » Thu Oct 12, 2017 6:31 pm

You probably wouldn't want to use the angle of the car to check if another was behind. What happens if your car is going backward on the track?
B
100
S
38
G
134
Posts: 5,552
Reputation: 85,317

Post » Mon Oct 16, 2017 2:56 am

Oh wow, someone just spotted my old thread.

Well, I don't really need this, but I may do this idea in the future. :razz:
SONAR Gamer's Club Discord |
Twitter | Facebook | Instagram

If you play Puyo Puyo games, you can meet me at the Puyo Puyo English Community Discord: https://discord.gg/0k41S8ARwvY2iTIQ
B
111
S
27
G
11
Posts: 702
Reputation: 13,223

Post » Sun Mar 18, 2018 11:45 pm

Message: lokippl can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
R0J0hound wrote:Keeping track of what waypoint the car is on is a way to give a very rough estimate of the rank. You can get a finer rank by also considering the perpendicular distance to the next waypoint.

So the event needed would basically look like this:

For each car ordered by waypoint*1000-perpDistToWaypoint decending
--- loopindex+1 is the rank.

If the distance between checkpoints can be more than 1000 change it to some higher value.

Ex.
https://dl.dropboxusercontent.com/u/542 ... /laps.capx

The perpendicular distance is the dot product between the waypoint line and the vector from the waypoint to the player. It can actually give us negative distances so we'll put it in a abs() so it's always positive.

Player = {x, y}
waypoint_to_player = {x-way.x, y-way.y}
waypoint_line = {cos(waypoint.angle), sin(waypoint.angle)}
perp_dist =abs( waypoint_to_player dot waypoint_line )=abs( {x-way.x, y-way.y} dot {cos(waypoint.angle), sin(waypoint.angle)} )
= abs((x-way.x)*cos(waypoint.angle) + (y-way.y)*sin(waypoint.angle))
vector


Can you reupload this example? If you still have it... Thanks!
B
4
S
1
Posts: 2
Reputation: 306

Post » Mon Mar 19, 2018 7:02 pm

@lokippl
link updated.
B
100
S
38
G
134
Posts: 5,552
Reputation: 85,317


Return to Beginner's Questions

Who is online

Users browsing this forum: inozz and 0 guests