Sign in to follow this  
jgranero

road curves

Recommended Posts

jgranero    122
Hi people. I'm working on a 2D top-down tile-based game that has its main focus on the roads and its sidewalks (its a highway road, not a closed circuit). I mean that EVERYTHING that might happen in this game will happen on the road. My car sprites are similar to those found on GTA in size and I choose to draw my tiles as 64x64 bitmaps. The problem is that I want the road to be highly detailed and I can't use only crossroads like those found in a city, I must represent curves (only one curve of 45 degrees would be nice). A straight is composed of two tiles and thats OK. But when it comes to curves, I have many small tiles to represent them and some of these tiles have only a small piece of the road on them (the rest is left blank for grass, sand, or whatever is in the background layer). The problem I got stuck with is: How will I deal with the cars trajectory and the surface friction coeficients as the car steps into a curve? I thought that I could enlarge my road tiles to 128x128 for instance to minimize the problem (or even 512x512, which is the total size of my curve) and then use bitmaps and/or vectors to deal with the surface and the trajectory issue. But at the end I got stuck here? Could somebody shed a light on me? Any idea would be appreciated. Thanks a lot.

Share this post


Link to post
Share on other sites
Wyrframe    2426
Well, for a given curve, you know the radius and the start and end angles, right?

Well, first check that your query point is inside the circle with the outer radius. Then, check you're also outside the inner radius. If either of these fails, you're not on the curve at all. Then, take a quick arctangent relative to the center of the curve-circle to check that your query point is inside the arc of the curve.

If you only have curves starting and ending at specific angles (like snapping to 45' or even 22.5', then you don't even need full arctangent, just an X:Y ratio check (ie for 45' locks, to ensure you're in the North-Northeast octant, X and Y must be positive, and Y must be greater than X).

[edit] Annotation; if you're using tiles, even better. Draw yourself a few circles, one with 3-tile outer radius, one with 4-tile outer radius, or whatever, chop these up into tiles. For these tiles, you can have a lookup table saying which circle it came from, where in the circle's arc it is, and where that circle is centered relative to the tile. Now, if a car is on a given tile, perform the "is this tile a straight or curve or nonroad?" test, and if it is a curve, look to the curve table. This is where you can also store surface slant information, if needed.

This entire tactic is superfluous if you make the jump to a true 3D polygonal world, however, mainly because there are better ways to approximate real-world physics once you have perfect-curve data or even just a mesh.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this