Hey, Im making a fps and have my gun rotating with the player. but at its hip fire position it doesnt fire in the center of the screen. I know how to make the gun “look at” the center using camera.viewportpointtoray and that works well.
I just dont know how to make the rotation script that makes it rotate with the camera work and look at the center.
The script for keeping rotation with the player is
targetXRotation = Mathf.SmoothDamp(targetXRotation , mainPlayer.GetComponent().xRotation , ref targetXRotationV , rotateSpeed);
targetYRotation = Mathf.SmoothDamp(targetYRotation , mainPlayer.GetComponent().yRotation , ref targetYRotationV , rotateSpeed);
transform.rotation = Quaternion.Euler( targetXRotation , targetYRotation , 0);
Could anyone help me with this?