Skip to main content
GameDev.net gamedev.net
🔒 Locked

Terrain Collision

Started by Gallivan Dec 20, 2008 at 1:14 PM 1 replies 1.2k views
Original Post
Gallivan
Gallivan
I have a list of units on the terrain (100 units or so). What I'd like to do is for each units "move turn" they should check if it's possible to move to that location. The only time it is impossible is if their final destination is an impassable terrain type. How should I store these terrain types? Should I store them as units and just test collision on them? This might end up in me iterating through both the Unit list and TerrainUnit list for every character... Are there any tutorials on how to perform terrain collision? I've searched for it but I mainly turned up results on collision detection (which I don't think is what I need...).
bluntman
bluntman
Surely you just check the terrain of the tile (or polygon or whatever) that the unit would be on in the next frame using its current vector and if it is impassable then do not allow the move. Sounds like maybe a data-structure problem. Do you have efficient means to determine what tile is under a certain coordinate/position? If you do I can't see what the problem is. Each tile will know its own type, so you just check the type to see if it is impassable.
If you don't then you should create one (if the tiles are on a grid then it should simply be scaling the coordinate by a certain amount, and that will give you an index into the tile grid).
gameXcore
gameXcore
Your wording is slightly confusing and perhaps lacking in details, how you do this will be down to the specifics:

- How is your data organised? Is your terrain a grid with each cell knowing whether it is passable or not, or is the terrain a large heightmap field with other ways of defining "impassable"
- If it is a grid, how many tiles can a unit move each "move turn", if its one then you will simply be checking whether that tile is "impassable", however if its more then one you are going to have to run a path finding algorithm to determine if a path to that position is possible and then act accordingly.

Alternatively, I have failed and read your question completly wrong :p

Scott
Game development blog and portfolio: http://gamexcore.co.uk

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.