- Home /
Recoil camera kickback help
Greetings!
I'm currently modifying an FPS kit and I'm trying to remove the camera reset after the recoil kick. I want it that everytime I shoot the camera kicks to a random x/y pos and stays there. I've been tweaking the code for 1-2 hours now but I can't seem to grasp my head around it, I'm still rather new at scripting, any help would be wonderful. Here's the code which handles the camera kick/reset pos.
//Set rotation quaternion to random kick values
kickRotation = Quaternion.Euler(Camera.main.transform.locRotation.eulerAngles - new Vector3(kickUpAmt * 2, Random.Range(-kickSideAmt * 2, kickSideAmt * 2), 0));
//smooth current camera angles to recoil kick up angles using Slerp
Camera.main.transform.localRotation = Quaternion.Slerp(myTransform.localRotation, kickRotation, 0.1f);
Here's an example of what I want specifically:
Answer by orkunsevengil · Aug 07, 2016 at 01:40 PM
I was looking around for ready made kits to learn how scripting works and find this game then extracted this script from a call of duty replica.I wish it works for you.When it's at ''0'' it behaves as you want.if you increase the value camera rasets to its orginal position.Im a designer and artist but a total newbie in scripting .Still couldnt understand what mathematics are going at the background:D
var returnSpeed : float = 0,0;
function Update () { transform.localRotation = Quaternion.Slerp(transform.localRotation, Quaternion.identity, Time.deltaTime * returnSpeed); }
Your answer
Follow this Question
Related Questions
How to make camera position relative to a specific target. 1 Answer
Recoil script not working, camera rotation 1 Answer
Camera recoil Help 0 Answers
[Solved]Top-down shooter camera recoil effect 1 Answer
lerping transform.position on a camera 0 Answers