# 2d racing game barriers

This topic is 3664 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi everyone, I am making a 2d racing game from top view for a mobile device. I am stuck for 2 weeks on how to make good barriers. The best I got is an sorted array of coordinates of where the barrier should be (about 6000 items). And what I'll do is that I have for(i=0;i<6000;i++) { here I test position of a car wiv each barrier coordinate and then do some action like change car's speed and angle} I there any simplier way? Because it gets significantly slower if the racing map is bigger and the barriers are longer (about 10 000 items). and of course there will be opponents so I am afraid this is not good solution. it must also be very precise because the graphics are in high detail. thanks for any advice. if you don't understand my system, that's probably because it's crap. :)

##### Share on other sites
hello,
i'm thinking of...
1. Make the sprites "collidable" i.e. those that act as barriers have that special property
2. Make a collision map (perhaps similar of what you're doing) but more like a map of 0's and 1's that represent your actual map of tiles, 0's are not collidable objects and 1's are.

cheers.

##### Share on other sites
Create a grid system based on the car's position in the world. For example, every 5 units is one grid, then only perform your collision tests on barriers that are 'attached' to grids around the car's grid or within the car's grid, this will mean that the rest of the barriers are ignored as the car is not close to them.

You can then have pretty complex barrier collision if you wanted.

1. 1
2. 2
3. 3
Rutin
20
4. 4
khawk
14
5. 5

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633655
• Total Posts
3013186
×