Author Topic: Aiming algorithm  (Read 11072 times)

Offline volutar

  • Colonel
  • ****
  • Posts: 355
  • Vanilla digger & Quality assistant
    • View Profile
Aiming algorithm
« on: March 02, 2015, 07:59:40 pm »
I know it's internal thing, but I still want to share my thoughts about aiming algorithms used in OpenXcom.

As I remember, initially (when Daiky started Battlescape) OXC was using simplest method of choosing the voxel to hit. It was either the middle of unit, or 3/4 of the height (to target the chest/head). Just two points. Yeah, that simple.

Then I changed that, made something vanilla alike, but with more precise height scanning (in vanilla it's 4 different height levels, and I made it scan each 2nd voxel). For each height level, starting with the middle, it tries 5 different inner voxels - central, and 4 at each side (depending on unit width, at the north, west, south, and east side).

After that I thought that I might scan unit more "optimized" way, using trigonometry, and turning target "plane" facing towards the shooter. So I had to check only 3 voxels instead of 5, for each level (plus top and bottom).
And it's how it works right now, pretty optimized, imposter-like shooter-aligned plane.

But in fact, it heavily suffers from the "obstacle" factor. In short - it always choses the available target voxel closer to the center of the unit. Even if it's next to wall or fence. So it often happens, that shown chances (which might be even 110%) doesn't reflect the reality, just because there are chances to deviate 1 pixel aside, and it will hit obstacle.



Target at the right will be hit with much more chances than target at the left, inspite of exactly the same distance. Because of obstacle issue. Random deviation is shown with highlighted ellipse. Without any obstacles it would be 100% chances to hit. But in fact, it will be 80% for the target at the right, and just around 30% for the target at the left.
It often happens when target is above and you're shooting and hitting the roof tile (which is obviously almost impossible, because you see only 1 voxel of the roof, being at the ground level), or targets at the corners. Sounds familiar?

I want to change that. I'm experimenting with aiming algorithm which gonna target the most visible part, not just the center.

Here are 3 different scenarios, blue is an obstacle or "miss", number is an aiming weight value. The more the number, the more chances this target voxel has when aiming.
First two are from the example above, and the third is "target behind the fence" (which is also often the case).



With these changes made, you hardly would be able to hide over the corner or behind the gear. Neither aliens. So battles will become slightly more brutal, and quicker. But hey, isn't this "dumb miss" the thing you always wanted to get rid of, and was often pissed off about?
« Last Edit: March 02, 2015, 08:12:47 pm by volutar »

Offline Yankes

  • Commander
  • *****
  • Posts: 2127
    • View Profile
Re: Aiming algorithm
« Reply #1 on: March 02, 2015, 08:13:33 pm »
I think this is too "precise", something like that should be reserved only for aim shot, not snapshot or auto that are done in general direction of enemy.

Offline volutar

  • Colonel
  • ****
  • Posts: 355
  • Vanilla digger & Quality assistant
    • View Profile
Re: Aiming algorithm
« Reply #2 on: March 02, 2015, 08:16:59 pm »
Snap and auto are already having low accuracy, so it doesn't matter which voxel is the target. It will mostly affect the aim.

Offline Arthanor

  • Commander
  • *****
  • Posts: 2560
  • XCom Armoury Quartermaster
    • View Profile
Re: Aiming algorithm
« Reply #3 on: March 02, 2015, 11:52:59 pm »
Cover is a difficult thing in XCom.

I think aiming for the "largest visible part" makes sense. Really you wouldn't aim for "just above a low wall" simply because the chest of your target is behind said wall.

That being said, in the example you gave above, I would tend to say that the guy hiding behind the stairs should be hit less often than the more visible one. It is a more difficult shot because the target area is smaller. Nothing to do with distance.

This makes me feel like both the placement of the "aimed point" (the "+" you drew) and the size of the hit zone are wrong. The "+" should indeed be at the center of the visible target, but the hit zone could afford to be larger so that being behind cover does benefit you.

In this case, a well positioned "+" would mean the left target has parts of its "hit zone" off target and parts obstructed by the stairs, whereas for the right one it would mostly/all be on target.

The "hit %" would then become something more akin to "% to hit a target at that distance without cover". If you really want to get into it, calculate the actual % to hit (% for the shot to be in the hit zone times % of the hit zone that is on target) and display that like the UFO extender accuracy %.

Moving your cursor about would show the odds of hitting something outside cover at that distance. Putting the cursor on a target without cover would display the same number. However, if the target has cover, the % would drop to represent how hard a shot it is depending of how much of the target is in cover. It would then open up a game of placement where you try to flank aliens in cover to get better shots at them.

Otherwise, I think the aiming should be for the chest, relatively large hit zone that will overlap cover. Complicating the game in order to ignore cover and simplify gameplay by making each shot at a given distance land with the same chance would remove a tactical element, which would be a lot or work for a sad outcome.
« Last Edit: March 03, 2015, 12:09:42 am by Arthanor »

Offline hellrazor

  • Commander
  • *****
  • Posts: 2193
  • Deep Ruleset Digger & Bughunter
    • View Profile
    • Github Account
Re: Aiming algorithm
« Reply #4 on: March 02, 2015, 11:54:30 pm »
Snap and auto are already having low accuracy, so it doesn't matter which voxel is the target. It will mostly affect the aim.

I can not concur, since i love hiding behind the gear :)

Offline tollworkout

  • Commander
  • *****
  • Posts: 665
    • View Profile
Re: Aiming algorithm
« Reply #5 on: March 03, 2015, 01:10:00 am »
i'm with volutar on this one. i think is fair to assume when you aim at something you aim at the visible component and not just the center.

you could make it so firing accuracy of the unit can affect this deviation  69 or under is regular game mechanic 70 and over is volutar's mechanic. so not everyone shoots perfectly.

Offline volutar

  • Colonel
  • ****
  • Posts: 355
  • Vanilla digger & Quality assistant
    • View Profile
Re: Aiming algorithm
« Reply #6 on: March 03, 2015, 05:23:44 am »
Arthanor,
why do you think I'm worried about the numbers at the UfoExtender cursor? Frankly I don't give a shit about it (I'm not a fan of this mod). I've started this because of initially bad aiming algorithms.
You've mentioned "tactical elements". I'm naming them "exploiting algorithm/AI flaws". As with dropping weapon with MCed alien, and be 100% sure it will never pick it up.

Really bad reference for the tactics.
« Last Edit: March 03, 2015, 05:28:33 am by volutar »

Offline tollworkout

  • Commander
  • *****
  • Posts: 665
    • View Profile
Re: Aiming algorithm
« Reply #7 on: March 03, 2015, 05:46:18 am »
also little things like these  work both ways. yes they protect you guys  but when you see some alien and try to shoot it the stairs blocked your shot and next turn alien shoots stairs don't block it's shot cause of the way the aiming works all your guys die and you're like...VOLUTAR change this bitch before i smash something. ahahahaha ...im kidding btw. is just LOF is smart system but is not perfect. volutar is saying he can optimize it to be better a bit more intuitive or predictable.

original game has this annoying and hilarious common situation you see the guy but can't shoot. but what if you can shot but always miss (or mostly miss) due to the way aiming works. that's not good either.
« Last Edit: March 03, 2015, 05:47:53 am by tollworkout »

Offline vlad

  • Sergeant
  • **
  • Posts: 32
    • View Profile
Re: Aiming algorithm
« Reply #8 on: March 03, 2015, 07:06:25 am »
Its reasonable to believe that alien or operative is aiming at the area that can provide best hit ratio. It wont make the obstacle hiding obsolete, it will make it more difficult to find suitable one.
But i am little worried what that means on higher levels of difficulty and gameplay wise. There is already a lot of smoke screen usage, would that make players consider minimal movement or bringing artificial walls ?

Offline tollworkout

  • Commander
  • *****
  • Posts: 665
    • View Profile
Re: Aiming algorithm
« Reply #9 on: March 03, 2015, 07:18:21 am »
honestly on higher difficulty + on ufo defense/tftd those LOF "anomalies" are NOT cover because they don't have an objective calculable cover reduction mechanic. they are just side effects of using LOF. cover is simply run out hit and run back . 

then again these anomalies kinda function like cover by reducing hit percentage. but the reduction is not predictable.

the problem is i know fences and stairs and windows and doors with windows or things with holes in them or things that bend  do this but how much cover or hit percent reduction they provide is completely random magic nonsense.
« Last Edit: March 03, 2015, 07:20:59 am by tollworkout »

Offline hellrazor

  • Commander
  • *****
  • Posts: 2193
  • Deep Ruleset Digger & Bughunter
    • View Profile
    • Github Account
Re: Aiming algorithm
« Reply #10 on: March 03, 2015, 08:29:10 am »
original game has this annoying and hilarious common situation you see the guy but can't shoot. but what if you can shot but always miss (or mostly miss) due to the way aiming works. that's not good either.

Uhhh i just pounded a muton standing in front of a UFO Door, outside the ship with Plasma Rifle Snapshot fire from 6 Soldiers (all +70 Aim), who were kneeling at the upper edge of a hill and NOT even one of them scored a hit. If they moved up the hill completly (so they are on level 2 instead of 1), they can shoot and hit. I even tried aimed shoot all failed, guess this was such a case.

Offline volutar

  • Colonel
  • ****
  • Posts: 355
  • Vanilla digger & Quality assistant
    • View Profile
Re: Aiming algorithm
« Reply #11 on: March 03, 2015, 10:06:52 am »
Just to recap about accuracy number from menu or UfoExtender cursor.

This value has nothing with actual hit chance. It's just accuracy, "abstract" value, showing how many %% of bullets will go straight to the target voxel (which can be too close to obstacles, but still opened).

To find actual hit chance, you have to trace thousands of actual bullets, considering all the envronment. Tho it is technically possible, it's highly unnecessary.
« Last Edit: March 03, 2015, 10:11:02 am by volutar »

Offline volutar

  • Colonel
  • ****
  • Posts: 355
  • Vanilla digger & Quality assistant
    • View Profile
Re: Aiming algorithm
« Reply #12 on: March 03, 2015, 10:15:28 am »
original game has this annoying and hilarious common situation you see the guy but can't shoot. but what if you can shot but always miss (or mostly miss) due to the way aiming works. that's not good either.
It's inherent logic of geometry. You see units from level of eyes, you fire  units from level of shoulders. It it wouldn't show you "no line of fire" and allow you to fire, there are 146% of chances to hit some obstacle. That's that.

Offline tollworkout

  • Commander
  • *****
  • Posts: 665
    • View Profile
Re: Aiming algorithm
« Reply #13 on: March 03, 2015, 10:21:36 am »
aimed shots should fire from level of eyes..auto and snap should fire from level of shoulders.. and the focus point  should always be the center of most exposed part of the thing firing at

Offline volutar

  • Colonel
  • ****
  • Posts: 355
  • Vanilla digger & Quality assistant
    • View Profile
Re: Aiming algorithm
« Reply #14 on: March 03, 2015, 10:42:21 am »
aimed shots should fire from level of eyes
I also thought of that thing since I joined OpenXcom. But this origination point is not something to be changed that easily. It needs of deep and thorough estimating of consequences. Having no "no line of fire" for AIM shot at all pretty changes the game feeling.