Advertisement

Unit movement

Started by February 28, 2001 02:06 PM
1 comment, last by pasman 23 years, 11 months ago
Hi, I''m writing a RTS game, but I have a small problem: I keep my units in a structure like this struct unitstruct{ int mx,my;//the position of the unit in the map int dx,dy;//destination point BOOL moving;// if we must move ........ }units[100]; and I also have a function int pathfind(int unitindex) and an array which contains the selected unit (i''m talking about multiple selection) like this int selected[100]. I have a function TPOINT getcoord(int mousex,int mousey); which returns the map position of the mouse. to move a unit i set the dx,dy variables of the unit with a map coordinate and the i call pathfind which returns the path of the unit. 1. the problem is that if i have multiple units selected and i set a destination spot all units will be on the same map point. So the question is how to set the destination points of each selected unit so that it keeps its postion in the group? 2. how can i surround a building for example by seting the destination points? 3. how can i set the units to a formation group like AOE2 or Myth? Thank you --------------------------------------------------------- "When a man lies, he murders some part of the world. These are the pale deaths which men miscall their lives. All this I cannot bear to witness any longer. Cannot the kingdom of salvation take me home?" Cliff Burton - MetallicA
1. Well.. for the beginning I''d keep it at this.. just make sure your collision detection works, and make sure units will stop trying to reach the target when they''re close enough and can''t get any further. Fixed unit formations aren''t a good idea (apart from real formations as in AOE2). If you still want them (the player should be able to switch them on/off) you can implement them by declaring one unit the "leader" of the group, and set that all units will just try to keep their relative position to their group leader the same.

2. Just take the center coordinate of the building and calculate the points on the circle around it, or some approximation. Actually, a unit logic that does this intelligently without pissing off players is really difficult.

3. Mark all the units as belonging to the group and average their positions so that you get the "center" of the group. Then just advance the center position towards the destination and make sure all the units keep the same relative position to the center. Again, intelligently getting through bottlenecks and so on can get pretty complicated.

cu,
Prefect

Resist Windows XP''s Invasive Production Activation Technology!
Sanity is the trademark of a weak mind.
Widelands - laid back, free software strategy
Advertisement
Thanks Prefect, that helped me but now I have another "small" problem... the collision
detection. The only collision detection that my engine performes is when we search for the
path of a unit is that set to move: the pathfind function creates a matrix with the
size of the map and sets it with 0''s for walkable tiles and 1 for non. Then at the
coordinates of each unit we set an 1 so it takes it as a nonwalkable tile. I call the
findpath function only when the user pushes the right button (in my case). So I''m asking
U how to do this. I know the basis of col. detection but I didn''t manage to implemented.
Thank You.

---------------------------------------------------------
"When a man lies, he murders some part of the world.
These are the pale deaths which men miscall their lives.
All this I cannot bear to witness any longer.
Cannot the kingdom of salvation take me home?"

Cliff Burton - MetallicA

This topic is closed to new replies.

Advertisement