Recoil Animation

Hey guys.

I’m making a FPS with JME3.

I already have a gun that shoots, makes a muzzle flash and a sound.

Now I’m tryign to make it have a kickback animation : when you shoot it goes up as if the character wasn’t strong enough to control it.

I’ve tried using a cinematic, a quaternion… None worked.

What I have so far, is this :

fpsak.rotate(90, 0, 0);

But this makes he gun come up and never come back down. Plus, it is flashing, so you’ve got one chance out of two to be unable to see it once you stop shooting. (Shoots around 3 times a second).

If I try doing this :

fpsak.rotate(90, 0, 0);

fpsak.rotate(-90, 0, 0);

Nothing happens. Any help is greatly appreciated.

First of all Spatial::rotate takes radians not degrees. Do:

[java]FastMath.DEG_TO_RAD * 90[/java]

Or if your gonna be using 90 degrees for definite, then you could use FastMath.HALF_PI instead

fpsak.rotate(90, 0, 0);
fpsak.rotate(-90, 0, 0);
Nothing happens

That will just reset it back to zero, as its still the same frame.

Use Quaternion.Slerp (stands for Spherical linear interpolation) in the update loop over a number of frames. To go from still to up, then from up to still.

Alternatively you can do the animation in blender

Thanks !

I’m gonna test that out tomorrow, but I will probably need some help on how to make the gun take back it’s initial rotation if the player didn’t shoot for a certain period of time.[]=slerp#slerp

then just change the amount of slerp, by incrementing a counter in the update loop. I suggest going through all the tutorials again, if this isn’t clear.

Alright, I got it to work !
Thanks :slight_smile: