# Gun Recoil?

For my pistol, I was able to animate the gun to make it look as though there were slight recoil.
For the Assault Rifle, however, I want the gun to behave like it would in other games. I don’t think animating that would work too well, seeing as how it should be sorta random.

Is there a way to make recoil via Python, or even Logic?
Anything other than animating?

Recoil is not random. It is always a force from front to back as reaction to the force applied to the gas leaving the barrel.

I guess you mean the “moving out of aim” (I do not know what it is called in English). This are usually results from the reaction on the recoil force. E.g. it tuns away because it crashed against the shooters shoulder.

Anyway. It is not real it is a game and it should do whatever you want it to do (such as jumping while you are in the air ;)).

To get a random turn or motion you can still use animations. There are several ways to do that. In most cases people ask how to get random bullet directions (e.g. from a shot gun). This one is no difference.

• have one animation that forms a spiral around the center (the curve determines the likelihood of the poses)
• choose and play a random frame (random actuator + action actuator property mode)

One simple but not very real way of getting random spread of bullets is to define a deviation distance (or DD), like 5.0.

Then get the actual target location in 3d space:

[1.00,-5.00,12.56]

now for each part of the location (x,y,z) minus your DD and then add double the DD multiplied by a random float. The result will be the location ± 5.0.

You can then use get vector to that point and you can then align your gun to that point.

It’s not very realistic because the result is a box, not a sphere, but it is pretty quick.

If you want the recoil to increase after each shot you can increase the DD. You can also base the DD on distance to target, player movement, stance and a whole host of other factors to get a nice fake realistic system.