Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

What's the best way of representing surfaces in a 2d top down racing game? I'd like paved and dirt surfaces in my game to have different friction properties. Would you break up the map into a grid and simply check where in the grid the car is to determine the friction? Or is there a better way of managing it?

The roads and dirt are not self contained all or nothing tiles either, so I'd have to handle a grid section that contained some road and some dirt.

share|improve this question
1  
I think part of the reason why you haven't received a response yet is that it's not entirely clear what's your problem. Are you asking about how to handle the collisions in general (collision detection?), or is your problem of some other nature? It might help if you show what you tried so far, and why it didn't work. –  TravisG Jul 20 '11 at 5:04
    
Sorry, I haven't had a chance yet to put in more information or explain in detail what I had done. I'll do a better job with future posts. –  Dylan McClung Jul 21 '11 at 21:09
    
What @Flip wrote explains what I'm looking for. –  Dylan McClung Jul 21 '11 at 21:10

2 Answers 2

up vote 2 down vote accepted

It sounds like the root of what you're asking for is a way of determining the friction of the ground at a given point in your map.

A simple way of doing this could be to create a one-channel (grayscale) texture that represents the friction of the ground. Sample this texture at the point of the car (or each of the four wheels if you're feeling fancy) to get friction at runtime.

These textures should make it relatively easy to author content for. You could probably whip up a debug mode that overlays the friction map on top of the visual texture to double check that things line up right. It allows you a lot of freedom in the friction gradient at the fringe of the road. You could probably come up with a data structure that uses less memory, but with a top down sprite based game I'm guessing that's not going to be much of an issue.

share|improve this answer
    
That's a great solution, I hadn't thought of doing it that way. You're right that the game world is small enough to use something like that. The grid I came up with wasn't great for cells that covered both road and dirt. I didn't want to make the grid cells smaller and smaller either. –  Dylan McClung Jul 21 '11 at 21:12
    
Also, thanks for interpreting the ambiguous question. –  Dylan McClung Jul 21 '11 at 21:14

I think what you're asking is 2D polygon collision detection: detect that the car shape is over a certain road shape, and then apply some physics effect like slowing down to the car.

This site has pretty pictures and has code that does what you're asking for, although you could probably pull it off just with bounding box collision detection. It really depends on what your game will really look like; "The roads and dirt are not self contained all or nothing tiles either" is somewhat vague.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.