- Home /
Non uniform movement radius
I've built a semi real time strategy game for work. I semi because users are restricted in their actions in turns. Anyways to the point. The user is allowed to move w/in a certain radius of their character BUT that radius isn't uniform at all degrees. The idea is that player can't move as far if they are restricted by say trees, hills, etc. In effect the movement radius becomes a blobby structure.
My problem is I'm not sure how to go about doing this in any sort of quick manner. It doesn't have to be real time but it can't take 20 minutes either.
My first thought was to project rays out from the selected unit and, at a set interval along that ray, shoot a ray cast down through my terrain. This would return a value that I could add to that ray giving my a sense of how many movement points that particular line would cost. But it seems to me that would still be costly. Additionally I've not any sort of idea how you would display something like that on the terrain.
I'm hoping someone might have some suggestions of places to look or similar problems I can reference.
Answer by · Jun 17, 2010 at 01:01 AM
I've seen this done (outside of Unity) by using a (typically-hex) grid system. Each unit is given a max-move distance and each grid is assigned a move-cost value.
Example Move-Cost values:
Plains = 1
Sand = 1.5
Hills = 2
Forest = 3
Marsh = 4
Cliffs = 6
Then, for example, a unit might have a max-move distance of 12, so it could move 12 along plains, 8 along sand, 6 along hills (etc), or a combination - i.e. the unit could move through 4 'plains' grids, over 2 'hills' grids, and 1 'marsh' grid (a total of 12 'movement points').
You can get even trickier and apply a modifier to grid-types move-cost values for particular units. For example, light infantry (or the equivalent for whatever theme you're using) might have a bonus against cliffs; i.e. they can scale cliffs easier than heavy units, so it only costs them 4 movement points rather than 6.
As for implementation, it would probably be easiest if you could select the unit and then (using the mouse position), the game could attempt to draw the cheapest path (lines) to the grid that the cursor is over.
Of course, this all depends on your intended implementation - do you want a completely free movement system, or grid-based navigation? A player could easily 'game' a free movement system by very narrowly passing any obstacles.
In either system, you'll need to tag the ground with some sort of 'type' and apply a cost factor against the attempted move. In a grid-based system, you can just store each grid ID and type in an array. In a free-movement system, ray-casting to the ground could potentially give inaccurate results, as the unit could completely pass through a higher-cost grid type before the next test interval. As far as performance costs, I'm not familiar enough with Unity to say how detrimental the frequent raycasts would be.
Hopefully these thoughts are of some use to you!
Your answer
Follow this Question
Related Questions
RTS camera help 1 Answer
changing camera view 3 Answers
Raycast help! 1 Answer
How to make a minimap camera zone grow bigger and smaller with zoom 0 Answers
Help with FOV script 1 Answer