Gun recoil kick movment
Im using this code to get the forward angle of the camera and applying force away from the camera to simulate the force of the gun being fired. This force will work to allow mobility when in the air. I can't seem to figure out how to find the angle of the camera from getcomponent().main. I have been working at this and still can't fix the error (CS0176: Member 'Camera.main' cannot be accessed with an instance reference; qualify it with a type name instead. ) thats probably the reason it won't work but I can't find what the type name should be.
public class knockback : MonoBehaviour
{
public float force = 10;
void Update()
{
if (Input.GetMouseButtonDown(0))
{
GetComponent<Rigidbody>().AddForce(GetComponent<Camera>().main.transform.forward * -force);
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612063959im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Orbit camera with mouse control script problems 1 Answer
viewing on the Mouse Y axis not working. 0 Answers
FPS camera looks the client 0 Answers
Camera becomes snappy when I build and run my game. 0 Answers
How to make Vertical Camera Recoil 0 Answers