I am making a First Person Shooter as sort of an introduction to programming.
I have separate scripts. one handles movement and camera rotation, one handles spawning the bullets and applying a force to them, and the last handles specifics of shooting a bullet.
However, I would like to make it so whenever a bullet is instantiated, the camera rotates simulating knock-back in a way; but I’m not quite sure how to do that. Here is my code:
void Update () {
Quaternion x = Quaternion.Euler (Input.GetAxis ("Mouse X"));
Quaternion y = Quaternion.Euler (Input.GetAxis ("Mouse Y" + 3));
if(Input.GetButton ("Fire1")){
Camera c = Camera.main;
verticalRotation = Input.GetAxis ("Mouse Y");
c.transform.localRotation.Quaternion.Euler(x,y,0);
}
}
In this, I’m trying to store the camera rotation in Quaternion angles, and add 3 to the camera’s vertical rotation nudging it up a bit. Is this a viable way of doing such a thing and I’m just missing something, or should I go a completely different route?