- Home /
How to make Recoil Dampening aka. Recentering?
So i have a system that makes camera move after shot (basic recoil system) It only goes to a certain pre-defined point with use of Slerp function (to make it look smoother) yet doesn't go back to the point where camera was initially facing -> it goes up but after that it doesn't go down.
At first all of this was made intentionally but now i want to add the Recentering (aka camera moving back some amount of time after to where it was facing before shooting)
There is the original code with mouse input sampling and applying recoil to then send it to script performing rotation (i cutout some parts to make it clearer):
private void Update()
{
// Mouse X rotation (Y axis) + Recoil Y axis
float _yRot = Input.GetAxisRaw("Mouse X");
_rotation = new Vector3(0.0f, _yRot, 0.0f) * lookIntens;
_rotation.y += cameraRecoil.y;
// Mouse Y rotation (X axis) + Recoil X axis
float _xRot = Input.GetAxisRaw("Mouse Y");
_camRotationX = _xRot * lookIntens;
_camRotationX += cameraRecoil.x;
// Setting cameraRecoil value
cameraRecoil = Vector3.Slerp(cameraRecoil, Vector3.zero, 0.25f);
// Applying to PlayerMotor
motor.Rotate(_rotation);
wepRotating.WepRotatorY(_yRot);
motor.RotateCamera(_camRotationX);
wepRotating.WepRotatorX(_xRot);
}
public void GetRecoilValue(Vector3 _cameraRecoil)
{
cameraRecoil = _cameraRecoil;
}
Where "cameraRecoil" is a semi-random Vector3 value received after each shot from another script operating on various stats of different weapons ;
"motor" and "wepRotating" are script to which im sending values to perform certain actions
I was trying a few things like subtracting cameraRecoil from the current camera rotation or accumulating cameraRecoil values from Slerp function and waiting till cameraRecoill is low enough so i could rotate it back.
However as it should work for both automatic weapons (where consecutive shots make it so previous cameraRecoil value doesnt have enough time to apply fully before receiving next value and new rotation is performed while previous Slerped value is fe. halfway to zero) and for slow firing ones (where the recentering speed and time after which it is performed is pretty important) there was always a flaw where either camera went to much (on full-autos) or too little down (on semis)
Now the question is how do i make the camera behave so it can work when cameraRecoil is fully Slerped and not? Or is there another way of making recoil recentering?
Your answer
Follow this Question
Related Questions
Camera Recoil,Please help me. 2 Answers
FPS Weapon inventory script help 0 Answers
Managing different weapons in scripting. 4 Answers
Swapping Weapons In Game 0 Answers
Adding objects on player models in a multiplayer game 0 Answers