Jump to content

Determining Starting Positions of Cars (Top-Down Racing)


SamStorms
 Share

Recommended Posts

Hello, everyone. I've previously posted here before regarding my university project, and you all were very helpful in figuring out the solution to my issue. That's why I've decided to discuss something with you again that has been hindering the development on my project.

 

The project is a real-time multiplayer top-down car racing game in which the host of a game selects a route of his/her choice via Google Maps, and the app makes a racing track out of the shape of the route (point-to-point race track, no laps).

 

Now, the first issue that I'm having is determining the starting positions of all the cars on the race track. Basically, what I'm doing is taking the array of points returned by the Google Maps API and converting them into Cartesian coordinates, then putting a rope object on those coordinates with a road texture.

 

Right now, I just have the cars start out at the first point in the array rotated in the correct direction of the track. This is the code of the module that converts the route coordinates into Cartesian coordinates, determines the starting direction of the car, the starting point of the car and the X and Y bounds of the world. I've just put this here in case its relevant and in case someone would need to see it to help me out.

var startingDirection, startingPoint, maxX=0, maxY=0, points = [];function trackGen(scale, xOffset, yOffset){	temp = JSON.parse(localStorage.pointsArray);	for (i in temp)	{		points[i] = {};		points[i].x = temp[i].lng + xOffset;		points[i].y = temp[i].lat + yOffset;		maxX = maxX < points[i].x * scale ? points[i].x * scale : maxX;		maxY = maxY < points[i].y * scale ? points[i].y * scale : maxY;		points[i].x *= scale;		points[i].y *= scale;	}	startingDirection = Math.atan2(points[1].y - points[0].y, points[1].x - points[0].x) + (Math.PI / 2);        startingPoint = {x: points[0].x, y: points[0].y};}

This is how it looks at the moment:

 

post-13520-0-76659400-1432963217.png

 

So if anyone can help me figure out how to calculate the starting position of the car, that would be great. Thanks for reading! :)

Link to comment
Share on other sites

  • 2 months later...

Wowww

 

Ohh man, How did it go with the project? How do you get the points with Google Maps?

 

I also want to build roads to make a racing game and to learn, is very interesting  :P

 

I'm reading the following tutorial http://www.gamasutra.com/blogs/GustavoMaciel/20131229/207833/Generating_Procedural_Racetracks.php

 

Regards, Nicholls

Link to comment
Share on other sites

  • 4 weeks later...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...