If anyone has played planetside 2, they will see that when the recoil resets, it will reset about exactly at the position the gun was at if you don’t move your mouse when you did the shot. I’m trying to make my the player rotate back to the original rotation. This was easy with vertical recoil because you are only rotating the camera up, but the recoil for the horizontal plane requires rotating the player in both the left and right directions. I don’t know how I can reset my player back to the original rotation for the horizontal plane and I’ve tried very hard to make this work. Any help would be much appreciated.
Basically when you shoot, a random range of my recoil is used for the horizontal axis. When I stop shooting, I want the player’s rotation to lerp or interpolate between the rotation the player is at when they just stopped shooting, to the original rotation the player had before they started rotating from the recoil. I want it to move back based on the net difference between the original rotation and the one that the player has right now.
I found out how to do it. Since it is a random value between negative and positive, it makes dealing with the horizontal recoil very difficult. The problem is that I am trying to get the horizontal recoil return back to it’s original position where it was fired and I’ve only been successful with the vertical recoil. So what you can do instead is use the rule of finding equal ratios instead.
Here is the ratio problem.
??? horizontalRecoilSubtraction
-------------------- = -----------------------------
verticalRecoilTotal horizontalRecoilTotal
The ??? is the verticalRecoilSubtraction value that I need in order to have a steady subtraction to it’s original position. So if we do some simple mathematics, the formula to finding out the verticalRecoilSubtraction value should look like this.
???(verticalRecoilSubtraction) = (horizontalRecoilSubtraction * verticalRecoilTotal) / horizontalRecoilTotal
I have it written like this, but it still works the same.
recoil.decreasedRecoilPerSecond = (recoil.amount/kickBack.totalAmount) * kickBack.recoveryPerSecond;
I suggest placing this in the Update function so that it will know the value before subtracting.