Hi guys, I can’t seem to figure this out. When the player fires the gun in my game, there’s recoil, so the camera jerks up, but the part I’m having problems with is slowly returning the camera/aiming reticle back to the original position. I’ve taken a look at http://hub.jmonkeyengine.org/forum/topic/recoil-animation/, but I can’t seem to wrap my head around how to manipulate the quaternions, and how to time the slerp function. Any help is greatly appreciated!
well first of all, you need the desired position.
the recoil of the gun (for simplicity we assume jsut a angle in the up direction)
the maximum allowed recoil (aka max 30degree from desired position
then always have the desired psoition, and independend
have the actual position that is desired position + current recoil
if shooting weapon add the angle via the angle maniuplators to the recoild, but make sure to clamp at the max recail angle. (to prevent a mg from turning you upside down ect)
now just multiplay your recoild angle with for example 0.2 per ms
recoild = recoil *tpf/0.2
eg in short
store where to look
store how much recoil this frame
compute new quaternion from where to look + the recoil angle
use this for the cameras rotation.