So, well, I'm making a TD, and the map has some "levels" units have to go through to reach the goal and steal players' life.
Between each level, I have some corridors. When the group of units complete a lap, one unit of the group accesses to the next level through a corridor.
The current layout is this one:
-Corridors between levels 1 and 2: 3
-Corridors between levels 2 and 3: 2
-Corridors between levels 3 and final: 1
With each lap, I want each corridor to let one unit pass. No more. To pass, the remaining units will have to complete the lap again and again, until all pass.
And I don't know how to exactly make that work properly. My main fear right now is that the group scatters across the level, be it because slowing towers or simply because the units in the middle were slaughtered. And... I don't have any idea on how to detect when a lap is completed. No freaking idea.
The only solution that I've managed to reach is add a timer to each corridor, so when an unit uses it, the next has to wait, let's say, 10 seconds. That way, when it becomes available, the entire wave has already gone straight past. But I still have the problem of the slowed units, and the timing could fail when the wave is huge.
Would it not work fine to just have a region covering the track at the end of the lap point to see when they've done one?
Then assign a value to each unit to track how many laps they've done, and when a unit enters the lap region you check all living units lap counts to see whether it can pass to the next area.
Don't actually know how you do custom values for units but to be lazy could just use the 'kills' value for each unit as it's a TD.
Unitgroup wave1 = [Last created units] (On wave creation)
Unit enters region lapRegion
Modify triggering unit kills: +1
boolean tempVar = true.
//If the unit is first to a lap it's kills will be greatest
//Hence check to see if any other units are equal or greater as it will imply it's the 2nd or more unit around.
pick each unit in wave1 and do:
if(triggering unit kills <= picked unit kills){
tempVar = false; //If another unit has more laps then unit shouldn't be moved to next area so false.
}
if(tempVar = true){ //Then you need to move the unit to next section.
//Move the triggering unit to next section or w/e you want to do with it.
}
Oh, well, I haven't still used the "wave" parameter yet, just group of units.
My main idea is to put the units in a unit group when they spawn, and then, each time an unit makes one lap, add +1 to a meter, and then, each time a unit of that group gets near one corridor, I check if every unit in the group has the same meter, and if it's true, then I open the corridor for that unit.
And yeah, using kills as the meter is pretty nice. I just have to change kills to laps in the UI and it would be fine.
I think, now that I'm seeing from a new perspective, that my problem was I was trying to work with the group instead of the individuals of the group. I already had a en-of-lap-region, but if I work with units one by one, it will work fine.
Also, I think I'll change the "group makes a lap" to "unit makes a lap". Using group is just bad. So:
LAP
-Unit enters end-of-lap
-Owner of triggering unit = player 9 (dunno if this line would be necessary if the units in the group are all player 9 xDDD)
-Unit is in unitGroup;
-Laps := Laps + 1;
CORRIDOR
-Unit enters corridor-gate
-Unit is in unitGroup;
-Lap count of unit == current lap
-Unit goes to next level
-Lap counter of the region increases
The only thing I need now is to use a local variable for the lap number required by the corridor. I could go one by one, giving each region its required lap number, which could work better than a local one, too.
Thanks again ;).
Update: Missed that last post... well, we got the same conclusion :P.
I'm polishing the final details of this, and I think I'm going to build an integer array with the number of corridors and then the number of waves, attached to each corridor-gate.
That way, each time an unit enters corridor-gate, it check if the unit's kills is the same number as the custom value from the array. If true, it means the unit is in the right lap, and it will open the gate and +1 the custom value.
Then, there's a end-of-lap region just before the corridors, that adds +1 to entering unit's kills.
Basically, instead of having a global variable for the number of laps, I have a variable for each corridor :).
So, well, I'm making a TD, and the map has some "levels" units have to go through to reach the goal and steal players' life.
Between each level, I have some corridors. When the group of units complete a lap, one unit of the group accesses to the next level through a corridor.
The current layout is this one:
-Corridors between levels 1 and 2: 3 -Corridors between levels 2 and 3: 2 -Corridors between levels 3 and final: 1
With each lap, I want each corridor to let one unit pass. No more. To pass, the remaining units will have to complete the lap again and again, until all pass.
And I don't know how to exactly make that work properly. My main fear right now is that the group scatters across the level, be it because slowing towers or simply because the units in the middle were slaughtered. And... I don't have any idea on how to detect when a lap is completed. No freaking idea.
The only solution that I've managed to reach is add a timer to each corridor, so when an unit uses it, the next has to wait, let's say, 10 seconds. That way, when it becomes available, the entire wave has already gone straight past. But I still have the problem of the slowed units, and the timing could fail when the wave is huge.
Any ideas? all the feedback is appreciated =).
No ideas? :(
If needed I could explain the wave system better :S.
@Lonami: Go
Would it not work fine to just have a region covering the track at the end of the lap point to see when they've done one?
Then assign a value to each unit to track how many laps they've done, and when a unit enters the lap region you check all living units lap counts to see whether it can pass to the next area.
Don't actually know how you do custom values for units but to be lazy could just use the 'kills' value for each unit as it's a TD.
@Smoothsmith: Go
Uh, so you mean assigning each unit it's own lap number?
It's a good idea, gotta try it. After all, i can 't make the same with a group, as I stated before (slowed and killed units make it hard).
Thanks a lot, man ;) :).
On a more of a pseudocode style -
Unitgroup wave1 = [Last created units] (On wave creation)
Unit enters region lapRegion
Modify triggering unit kills: +1
boolean tempVar = true.
//If the unit is first to a lap it's kills will be greatest
//Hence check to see if any other units are equal or greater as it will imply it's the 2nd or more unit around.
pick each unit in wave1 and do:
if(triggering unit kills <= picked unit kills){
tempVar = false; //If another unit has more laps then unit shouldn't be moved to next area so false.
}
if(tempVar = true){ //Then you need to move the unit to next section.
//Move the triggering unit to next section or w/e you want to do with it.
}
Humm or another thing you could do is have a global counter variable which you increment each time a unit goes through.
Then you just check if an individual units kills are > counter and if so -
Increment counter
Move unit to new area.
Shoulda thought that before it's way easier -_-
@Smoothsmith: Go
Oh, well, I haven't still used the "wave" parameter yet, just group of units.
My main idea is to put the units in a unit group when they spawn, and then, each time an unit makes one lap, add +1 to a meter, and then, each time a unit of that group gets near one corridor, I check if every unit in the group has the same meter, and if it's true, then I open the corridor for that unit.
And yeah, using kills as the meter is pretty nice. I just have to change kills to laps in the UI and it would be fine.
I think, now that I'm seeing from a new perspective, that my problem was I was trying to work with the group instead of the individuals of the group. I already had a en-of-lap-region, but if I work with units one by one, it will work fine.
Also, I think I'll change the "group makes a lap" to "unit makes a lap". Using group is just bad. So:
LAP
-Unit enters end-of-lap
-Owner of triggering unit = player 9 (dunno if this line would be necessary if the units in the group are all player 9 xDDD) -Unit is in unitGroup;
-Laps := Laps + 1;
CORRIDOR
-Unit enters corridor-gate
-Unit is in unitGroup; -Lap count of unit == current lap
-Unit goes to next level -Lap counter of the region increases
The only thing I need now is to use a local variable for the lap number required by the corridor. I could go one by one, giving each region its required lap number, which could work better than a local one, too.
Thanks again ;).
Update: Missed that last post... well, we got the same conclusion :P.
:D Awesome, nice to know you seem to have it sorted.
I'm polishing the final details of this, and I think I'm going to build an integer array with the number of corridors and then the number of waves, attached to each corridor-gate.
That way, each time an unit enters corridor-gate, it check if the unit's kills is the same number as the custom value from the array. If true, it means the unit is in the right lap, and it will open the gate and +1 the custom value.
Then, there's a end-of-lap region just before the corridors, that adds +1 to entering unit's kills.
Basically, instead of having a global variable for the number of laps, I have a variable for each corridor :).
I'll post the code later if it works ;).