Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411469 Posts in 69368 Topics- by 58422 Members - Latest Member: daffodil_dev

April 23, 2024, 03:56:52 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Find "Place" in a racing game
Pages: [1]
Print
Author Topic: Find "Place" in a racing game  (Read 906 times)
Mightymcc21
Level 0
*


View Profile
« on: July 30, 2015, 02:28:01 PM »

Hey, everyone.

I'm currently developing a 2D top-down racing game in Unity and I've come across a hurdle I can't seem to get over. I'm trying to figure out how to calculate the placement of the player and CPU opponents (I.E. 1st, 2nd, 3rd, etc.) but so far my attempts have failed. I was wondering, is there a known, accepted way to find the place of an object in racing games and if so what is it?
Logged
Ashedragon
Level 2
**



View Profile WWW
« Reply #1 on: July 30, 2015, 05:34:08 PM »

If I were to make a racing game I would give each vehicle a "distance" variable and add to that distance when they're moving forward on the track, and then simply compare this variable to determine placing.
Logged

Cheesegrater
Level 1
*



View Profile
« Reply #2 on: July 30, 2015, 05:34:25 PM »

You should be doing path finding between the racers and the finish line - just sort them based on the remaining distance along the path. Checking the docs, unity makes that accessible as remainingDistance on a NavMeshAgent component.
Logged
Mightymcc21
Level 0
*


View Profile
« Reply #3 on: July 30, 2015, 05:55:46 PM »

Ashedragon - That's what I originally attempted but my opponents are prefab clones and I was having trouble reading their variables in a separate code.

cheesegrater - That sounds promising, I'll look into it.

Thanks to both of you for the help.
Logged
diegzumillo
Level 10
*****


This avatar is so old I still have a some hair


View Profile WWW
« Reply #4 on: August 01, 2015, 05:25:42 PM »

Cheese's idea is the simplest I think. Another way is to treat this is a math problem; define the track as a curve c: t-> (x,y) (t=0 gives the start of the track and 1 the end of the track) and during run time you calculate the closest point inside the curve to each car and define that as the car's position in the track, then compare the positions. Might require some algebra knowledge but it's easier than it sounds.
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic