Jitter

Started by
3 comments, last by jonbell 20 years, 4 months ago
I have 2 entities firing at each other and i want the accuracy of the shots to depend on the distance. When i do my calculations i get the target position vector for the shot and i want to ''jitter'' it but clamp the range to between 0 and x where i specify x. So given a distance d how can i express that float between 0 and x so that as the greater the value of d the closer it will be to x.
Advertisement
How about..

f(x) = x - kx / d² = lim(d -> infinity) x
f(0) is division by zero and thus undefined.. Although that shouldn''t be too much of a problem, as two entities seldom(read: never) exist in the same place at the same time. So d > 0.

However since you have the vector between the two you can just jitter that by some amount.. Like a very simple formula could be like this:
A shoots B, V is a random, normalized vector and D is the resulting direction at which the shot should be launched:
(||X|| means normalizing vector X)

D = ||(||B-A|| + V/k)||

So you shift the vector a little by adding a fraction of a randomized vector to it. k is the accuracy, a scalar; the higher k is, the more accurate the shot is. k > 1, unless you want shots the end up going backwards
delete this;
i suggest that you get a normalised direction vector that points from one entity to the other. Then you can modify the angle of that vector slightly (NOT based on distance) then use that as the direction of your shot.

This will have the same effect as "jittering" your shot based on distance...

To modify the angle i would suggest using a normal distribution, this will give you a good spread for your shot accuracy (i.e. most shots will be close to the target, few shots will miss by a large amount and then very rarely some shots completely miss their target). It is used in statistics. do a search for normal distribution
Ah, but if one modifies the angles then if for instance you look straight upwards the spread will be slim to zero when you convert it back to cartesian space. My method will work the same way no matter what direction you''re aiming at.
Although you might want to make sure you generate the random vector properly(there was a thread on that a while back in here. dig around).

delete this;
quote:Original post by Tjoppen
Ah, but if one modifies the angles then if for instance you look straight upwards the spread will be slim to zero when you convert it back to cartesian space. My method will work the same way no matter what direction you''re aiming at.
Although you might want to make sure you generate the random vector properly(there was a thread on that a while back in here. dig around).


Ok i see what you are saying... But i was thinking more of chosing a random rotation axis that is in the plane defined by the vector. Then using that rotation axis and a random angle obtained using a normal distribution to create a rotation matrix. Once you''ve got that you can rotate the vector with the rotation matrix.

Which will give an even spread no matter the orientation of the vector.

This topic is closed to new replies.

Advertisement