Aim at Something with Delay

Hi, all!

I was just wondering if there was a type of SmoothLookAt function that looks at the player’s position x seconds ago. This would be great to use for a simple enemy AI.

If there are no community scripts, does anyone know how I could do this? Somehow store the player’s position x seconds ago? This would be a great simulation of ‘accuracy’ (if the player is moving a lot, the player will generally not take much damage).

Hopefully this is the correct approach to basic AI shooting functionality. :wink:

Thanks! - YA

I wouldn’t do it that way.

just make an accuracy algorithm and factor in movement and distance.

what your really going to do is use an algorithm to find the radius of a circle and then RANDOMLY target 1 point inside that circle.

the algorithm can be as complex or as simple as you want. Here are some ideas though

accuracy = fired_recently * distance * ai_velocity * player_velocity * ai_base accruracy

fired_recently would be a number that KEEPS INCREASING up to a max value if you keep firing. It basically makes each shot successively less accurate.

the multiplying is imporant.
What you really need to do is sit down and ask yourself what things affect accuracy.
in the above i went with.

shooter velocity, target velocity, recoil(if you fired recently), distance to target, shooter skill.

Then you need to ask yourself how much each should affect it relative to a base amount.

if you say for example a prone sniper AI shooting at a a stationary target at close range(or whatever your best case scenario is) will hit somewhere within a 1 x circle.
it should be 1 of something. it could be 1 inch or for example it could be 1 half inch.
if it’s 1 half inch convert it later.
You want your base to be one for multiplying to work to produce 1 in a perfect case and be based off that for other cases.

Now what you do is

base = 1

and now everything is relative to the base

then how much would a moving target affect it. 3 times as much lets say, and how much harder is standing up than laying down? twice as much lets say

standing = 3;
crouched = 2;
prone = 1;

target_moving = 3;
target_still = 1;

ok then accuracy = target_moving * standing;
so its a 6 inch circle because its 6 times harder to hit a moving target while standing than a stationary one while prone.

you keep doing that for all your variables
remember though its all based on a base, that means each variable should have one possibility (and the best possiiblity) be 1.

so if prone is the best stance prone is 1.
You shouldnt have something that is less than 1 because that means someone could have an accuracy that is greater than whatever you think is perfect nearly (it’s natural to assume even the best shot wouldn’t PERFECTLY hit exactly what they aimed at).
The only reason for a value of less than 1 would be maybe an ability that improves accuracy for a short period.

so you now find the radius of the circle with the algorithm and then its just a matter of a function call to randomly pick a point within its bounds. send the bullet right at that point.

for example if its 3 times harder to hit while moving than