Ykkrosh, on 03 March 2010 - 09:05 PM, said:
Thinking about projectiles.
In the old system, it does an actual physics simulation - it moves the projectile according to gravity each simulation turn, finds all the entities whose footprints it crosses (in 2D), then looks for the first one (by entity ID) whose bounding box is tall enough to reach the arrow, and if it finds one then it hits it.
A few problems I see with this (in decreasing importance):
* We get very little gameplay control - we might want to say there's 75% less chance to hit units that are hidden in a forest, or a 25% greater chance to hit friendly units if you fire into the middle of a melee, etc, but it's hard to do that if we're doing turn-by-turn collision detection.
* Bounding boxes are a very rough approximation, and many objects are not shaped like boxes, so things will get hit even if it looks like the arrow is nowhere near a solid part of them.
* To make things look nice, the projectile ought to be launched from an appropriate prop point on the actor (currently it's just launched from 2.5 units above the ground), but we don't want the simulation to depend on the actor mesh data (because of floating-point inaccuracies, and because it's good to keep them independent).
* The collision detection sounds fairly expensive - it won't be much fun when you build a hundred archers and tell them to aim across the entire enemy army, and it has to check every arrow against every unit every turn, even if we have some optimised spatial data structures.
* It's lots of floating-point code, which is annoying to translate into fixed-point.
So I'm tempted to do something more like:
* Calculate a target point on the ground (based on what the user aimed at).
* Apply some randomness based on distance, archer skill, etc, to make things as inaccurate as desired.
* Compute who is going to get hit, based on their footprint and distance from the target point.
* Do some extra checks so that trees and walls can protect the target.
* Work out the time until the target will be hit (assuming it's going to hit somebody).
* Choose the visual 3D target point (typically the center of the target's bounding box, so that you'll never kill somebody by hitting them in an invisible corner; or a point on the ground if it misses everyone), and visual source point (based on the actor), and set up the projectile as a purely graphical effect so it moves in a nice arc between those two points.
* If the target unit moves in the future, adjust the arc so it's still going to hit it. (This is physically unrealistic but if projectiles move fast then nobody will really notice, and if they do notice then they won't really care. (I'm sure I've seen a few tank shells do 45-degree mid-air turns in Company of Heroes to hit their target, but never worried much about it.))
* After the previously-determined time interval, hurt the target.
That means all the work is done once, when the projectile is first released, where it will pick the target and do any special calculations to adjust probabilities of hitting, which helps with performance and control. The apparent motion of the projectile is purely a graphical effect, with no effect on the simulation itself, so it's simple and fast and can be tweaked to line up nicely with the actors.
This won't be great if we have big slow long-range projectiles (like catapults that launch burning cows) but we can extend it later and I think it should work okay for the common cases (arrows and javelins). Hopefully.
Wijitmaker, on 04 March 2010 - 05:27 AM, said:
So, if I read you right - any projectile fired will always find it's mark? (like a homing missile?)
Mythos_Ruler, on 04 March 2010 - 07:37 AM, said:
Ykkrosh, on 04 March 2010 - 10:16 AM, said:
I think they're needed (in a basic form) because otherwise people will build archers and javelinists and get quite confused by why they can't attack anyone and just sit there like lemons

. (I originally marked it as needed on
this page for that reason.)
Yes - it will decide what its mark is when it is first launched (it might miss the unit you targeted and hit somebody else, depending on accuracy), but then it will always hit that mark. (Unless the target dies before, or hides in a building, in which case I guess it'll just hit the ground). I don't like that, but I can't think of any alternatives I dislike less.
Wijitmaker, on 04 March 2010 - 05:34 PM, said:
I'm not sure I like that idea, but I'm not the one that has to impliment it. So take this for what it is worth...
This was a while ago, so perhaps things have changed. But years ago the idea behind the game design of ranged attack simulate real world warfare. Such as:
* Pierce Damage inflicts high HP lost vs units that don't have the correct armor (like shields, plate armor, chain mail armor)
* Accuracy diminishes with distance of the shot
* Accuracy increases with training
* Ranged units typically have lighter armor themselves and higher mobility
* Accuracy improves if they have time to take a good shot, decreases with movement
* Speed of the shot increases with strength/experience
So, that being said... If you have heat seaking missles that lock on targets, you are ignoring some of the gameplay and strategy that could be devised with ranged units. Not saying this is required feature right now, or perhaps ever... if it is overly complex to work some of these ideas into the gameplay.
So, I say all of this to say - that I think it would be best that if an entity marks a target, and fires - that shot should go to the target it picks the instant it fires, it shouldn't deviate to follow the target.
If it misses the mark, it would be because the unit moved. Now, I could see that a good archer could "lead" his target to guess where the target might be when the arrow reaches the target's distance. Perhaps that could be a tech that would 'lock' and allow some deviation by a small margin?
So, in summary... greater the distance, slower the speed of the shot, and movement by the target - the less likely it would be to find it's mark. And, that isn't always a bad thing - it happened, probably often

Ykkrosh, on 04 March 2010 - 07:11 PM, said:
I think all of the things in your list can still be done, because they can be computed when the projectile is launched rather than when it reaches its target - the approximate distance to the target is known, and all the characteristics of the attacker are known, so accuracy can still be simulated. The accuracy computation could also be based on the speed of the target at the time of launching, if we want moving units to be harder to hit.
The only thing that couldn't have an effect is any movement of the target
after the launching - once the projectile has decided to hit the target and has then been launched, it's definitely going to hit the target. So you can't wait until the enemy fires at your units then quickly pull your units back so that the arrows harmlessly hit the ground in front of them, and you can't make a group of tall bodyguards run in front of your hero to protect him after the enemy has fired.
I've only ever done archery with modern bows and over short distances and I'm far from an expert (and far from really knowing anything at all about this), but I'm not sure that getting shot at and then quickly running away is a historically viable strategy.
Apparently most bows get somewhere around 90mph, and apparently Roman archers got a maximum range of around 200m, which gives at most five seconds to run away, so I don't think that's a tactic you'd want to rely on.
I think the reason I'm worried about not deviating is that it's hard to make the graphics match the decision of whether the unit gets hit. We can't do precise tests against the target unit's mesh polygons, so we have to approximate using a bounding box (or bounding cylinder), and then it's likely to unexpectedly hit what the player sees as empty space around a unit. Making the bounding boxes tighter would reduce the chance of anyone ever getting hit, so we can't simply do that. (I doubt it would be much fun if you fired a few dozen arrows into the middle of an enemy concentration and only one got a hit).
Units should always appear to get hit somewhere near their center (where they're nice and solid), but we need more control than is possible by adjusting bounding boxes, so the graphics needs to be separate from the gameplay decisions about accuracy and probabilities of hits. And the only way I see to keep those things separate but consistent is to make the arrows deviate so they hit the chosen spot. (They should never deviate much, because they're fast and the target is slow, and we can say it's wind if anyone notices.)
(I'm certainly not convinced that I'm correct here, so this is a useful discussion

. I think it's a tradeoff between various groups of problems, and it's good to have as much information as possible.)
Wijitmaker, on 04 March 2010 - 08:11 PM, said:
I see your dilemna better now. You mentioned adjusting the bounding box, is it possible to shrink the bounding boxes on the fly and make the 'core' of the unit the target, rather than the entire bounding box that define the extents of the mesh?
Would you be able to control the amount/degree of deviation?
WhiteTreePaladin, on 04 March 2010 - 08:57 PM, said:
That is classic. I think it should go in an FAQ eventually.
I thought about that too, but it seems that might still be too much computation to do for each shot (considering how many arrows could be shot at once)? I'm glad you started this very interesting discussion, Jason.

Ykkrosh, on 04 March 2010 - 09:46 PM, said:
That's technically possible - but if the boxes used for projectile collision detection are small, it'll be unlikely that an arrow will hit anybody, because a group of units will mostly consist of empty space between their little boxes.
It would probably be 'realistic' for most arrows to miss everybody, but our game isn't a realistic scale: we have tens of units instead of hundreds or thousands, units are metres apart rather than packed shoulder-to-shoulder, battles take minutes rather than hours, we build cities hundreds of metres apart from each other, and so I think we need independent control over the scale of arrow-hitting-target probabilities in order to balance it.
Not quite sure what you mean here. Once a target unit is picked (taking account of accuracy and hit probabilities) it would have to deviate as much as is necessary so that it will continue to move towards that target.
Wijitmaker, on 05 March 2010 - 05:44 AM, said:
I was curious if you could specify (for example) the arrow can adjust it's course by 10 degrees to find it's target while in flight. If it exceeds that, it would miss. But, it sounds like the arrow will do whatever it takes to get the job done. Like you say, if the arrows are flying fast enough, I doubt anybody will notice. Only way to find out for sure is to program it, and play it

I'll leave that in your capable hands
Oh, another factor to throw in the archer mix to consider is the rate of attack. As you have probably experienced - if you have time to take a good steady shot, your likely to have higher accuracy.
Mythos_Ruler, on 05 March 2010 - 09:48 AM, said:
Hmm, what about this.
When the projectile is thrown at a target the "target" is actual any random area within a small radius of the spot on the grid where the target was when the projectile is launched. Adds some accuracy realism (maybe this circle becomes smaller for Advances and Elite units). If it hits the target, then great.
Side note: Why can't the bouncing boxes be manually adjusted for uber excellence in the entity?
Second Note: why not just do it exactly how they do it in Age of Mythology or Age of Kings? Maybe you'd need to see the source code though for that.

Ykkrosh, on 05 March 2010 - 12:25 PM, said:
I think that's what I'm already thinking of (but probably not explaining well

) - the player picks a specific point to aim at, then the game does some calculations based on accuracy and range etc to choose where it'll really hit, which will either be a unit that's close to the targeted point (though not necessarily the one the player clicked on) or a point on the ground (if it misses everyone). With more skilled units, the chosen target will be closer to the point the player selected (and more likely to hit a unit rather than empty ground).
Because the bounding boxes affect both the probability that a unit will be hit, and a how a unit will be sheltered by those nearby (especially trees and buildings), and how close an arrow appears to come when it hits the unit. I'm not sure it's possible to choose a bounding box size that is good enough for all of those things simultaneously.
Hmm, that's a good idea. So I looked at AoM, and arrows diverge from their normal path in order to track their target unit. (It's much easier to see if you reduce the velocity of arrows, and then make a guy run around while being shot at - the arrows move really weirdly to make sure they land on him.)
AoM actually has a "TrackRating" in proto.xml which affects this - if it's high (which it is by default) then the arrows try hard to follow their target, and if it's low then they lag behind and are more likely to hit the ground behind a running unit. It's got some values for accuracy and spread too. I'm not sure exactly what it's doing (there's a lot of variables and it's hard to test), though I can see it's not the same as what I'm thinking of, but it does the same trick with making in-flight arrows track their target instead of doing a realistic physics simulation.
One thing I notice in AoM is that's hard to see exactly where a unit gets hit, which suggests it doesn't actually matter if we don't make it precisely match the solid body of the unit because nobody will notice. But I expect that's partly due to AoM's arrows being fast and frequent (toxotes seem to fire once per second) and about twelve inches thick - AoM feels stupid and cartoony with these Gatling-gun archery units firing a continuous stream of arrows at my unit that is zipping backwards and forwards, so I'm assuming we want something slower-paced where each individual arrow has a much greater significance. (The strongest memory I have of playing the AoM demo is how rubbish and insubstantial the archers seemed, so that's not something I want to completely emulate

)
Wijitmaker, on 05 March 2010 - 04:20 PM, said:
Good call on suggesting to review AOM, Michael

Interesting findings Philip.
Whatever you end up with will be great - looking forward to seeing it in action!
janwas, on 05 March 2010 - 11:51 PM, said:
I agree that the AoM archers were nigh worthless - IIRC only the Atlanteans (from the expansion) and a Greek mythical unit that fired volleys of arrows were worth their salt.
That aside, it seems reasonable to roll the dice and choose the landing point when the arrow is launched. To avoid the problem of deducting HP due to an arrow that lands next to the unit, tracking the unit sounds good. However, my recollection of CoH games is that people often noticed and commented upon the extremely visible projectile path changes. (In WW2, there were antitank guns with v0 of 1000 m/s, and any deviation at all is just laughable and annoying.) In fact, the gameplay element of moving away to dodge a volley of projectiles seems worth keeping, it'd be a shame to lose that in 0ad. Consider micromanaging a hero unit - it'd be a shame if his destiny were pre-determined, rather than at least partially dependent on skillful dodging/weaving.
Here's a simple potential solution: when firing, determine the hit position and the unit currently standing there. If the unit manages to move far enough away from that position, forget that it was the target. Otherwise, make slight adjustments to the rendered projectile position so that it'll appear to hit the unit.
Those extra checks you mentioned are a bit tricky, but probably also important for gameplay. Trees could be modeled by a single probability of not hitting anything, but those walls should stop everything to be convincing. We might get away with only checking a small fixed neighborhood of tiles around the firing and target position, and marking that as the new 'stop' position if there's a wall there (assuming trajectories aren't flat, which seems reasonable if trying to achieve ranges > 100m).
Mythos_Ruler, on 07 March 2010 - 01:35 AM, said:
Here's what I think arrows (and javelins) should be like:
- High Attack (jevelins higher attack than arrows because javelins have more mass, but consequently have shorter range)
- Infrequent Attack (archers should take a few seconds to nock their bows properly and aim)
- Quasi-synchronization (archers in a group tend to fire in volleys)
- Distance accuracy (projectiles are less accuracy at long range)
- Accuracy > Attack (Accuracy is more important than the attack value; accuracy adjusts from basic to advanced to elite; higher levels don't get higher attack, but rather greater accuracy)
And here's the tricky one:
- Ranged Units Anticipate their targets (archers and javelinists will lead their target in order to hit it; if the target changes direction then the projectile is avoided; this rewards micromanagement)
janwas, on 07 March 2010 - 06:29 PM, said:
That all sounds reasonable

One additional bonus for the elite might be firing frequency - is that desirable? It would prevent mixed-experience formations from firing synchronized volleys. To achieve that effect, is it sufficient to just order your units to stop/move, then attack something, and rely on them all reacting to the order at the same time, i.e. synchronized for that first volley?
I agree about micromanaging and the benefits of avoiding arrows (especially when considering single units). However, Philip is planning on first implementing the simple solution (just working out hit/miss before shooting and following the target unit), but attempting to keep open the possibility of the more complicated but interesting solution later. (We talked about this in the meeting. To achieve both square-on hits and allow dodging, we'd have to have the arrow re-acquire a target if the previous unit got far enough away from the intended intercept position, which is possible but a tiny bit more complicated.)
BTW, leading the target seems to be a freebie since we'd do the 'follow target unit' thing.
Ykkrosh, on 07 March 2010 - 07:31 PM, said:
Sounds reasonable to me too
An extra issue I encountered: For performance reasons, the simulation 'turns' are fairly slow (currently about 3 turns per second; could be increased to maybe 5 per second to reduce player input latency) and unit positions are simply interpolated when rendered between turns. Projectiles travel at a constant speed, so it might take e.g. 2.5 turns to reach the target. To make it look good, they need to be rendered so that they hit whatever unit they hit at its interpolated position between turns 2 and 3, but the actual simulation computations have to occur in either turn 2 or 3, and the unit could move by half a tile in that time. So just doing a test for "what unit is currently at the point where the projectile landed?" is not going to match what it looks like it hit. So I still think we need to cheat in order to make it look correct.
But it sounds like people really want to be able to dodge arrows, and I have approximately no RTS-playing experience so I can't justifiably disagree strongly

. Seems like maybe the reasonable approach is to do this tracking thing, so it looks okay in the common case and so we can easily control the probabilities of hitting a target, but if the target moves too far away from its expected position (where 'expected' is possibly based on leading the target) then the projectile will 'detach' and always harmlessly hit the ground (or (as Jan suggests) pick a new target).
In the interests of not taking forever to get an initial rough version working, and because this is becoming more complex than I expected, I think I'm going to give up trying to get it just right and will stick with my current implementation for now, and add lots of comments about how it should be modified (hopefully soon) to be better. (Currently there's a (ugly, hardcoded) 50% chance of hitting the unit you targeted, and the projectile locks onto that unit and always hits it (which is a reasonably subtle effect with the standard archer speeds); and 50% of hitting a random point on the ground nearby. (Arrows that hit the ground stay there forever, because it's nice to see where they landed). This isn't acceptable from a gameplay perspective, but it generally looks okay to me.)
WhiteTreePaladin, on 07 March 2010 - 09:21 PM, said:
Yes! That may fix more than just arrow issues; I always thought the response time for unit tasking was noticeably slow.
About the dodging arrows, I remember doing that with heroes in AoK, so it's likely that we'll want it here too eventually.