- Home /
Recoil script not working, camera rotation
So my game looked kinda bland and i wanted to add recoil to the main camera so when the AddRecoil function is called (through my main gunScript) it adds the amount to currentRecoil. Which sets the rotation of the main camera on the x axis. The currentRecoil is working so the error lies when i add it to the camera rotation. Could it be that i rotate the camera in an other script according to the mouse movement? And if it is that simple can i overwrite it or do i have to combine them which would be very annoying. Anyway i hope to get answers, thanks.
~Flux
public float maxRecoil = 50f;
public float recoilDecreaseSpeed = 2;
float currentRecoil = 0;
void FixedUpdate ()
{
currentRecoil = Mathf.Clamp (currentRecoil, 0, maxRecoil);
//decrease recoil all the time
currentRecoil -= Time.deltaTime * recoilDecreaseSpeed;
//set camera rot to recoil amount
Vector3 recoilRot = new Vector3(currentRecoil, 0, 0);
Camera.main.transform.eulerAngles = Camera.main.transform.eulerAngles - recoilRot;
Debug.Log (currentRecoil);
}
public void AddRecoil (float ammount)
{
currentRecoil += ammount;
}
Answer by fluxhackspro · Jun 25, 2018 at 05:58 PM
Sorry for the inconvenice but i fixed it and for anyone that needs a quick answer for a simple recoil script the one above works, and to have it work with an fps camera movement i used the following when setting my camera rotation in my movement script:
Camera.main.transform.localRotation = Quaternion.Euler (verticalRotation - GetComponent<RecoilController>().currentRecoil, 0, 0);
Your answer
Follow this Question
Related Questions
lerping transform.position on a camera 0 Answers
How to make camera position relative to a specific target. 1 Answer
Recoil camera kickback help 1 Answer
Camera recoil Help 0 Answers