- Home /
Question by
IkerCastillo · May 21, 2020 at 10:05 AM ·
fps controllerweaponsfps tutorial
How To Keep An Object In My Vision Range
Hello! I'm developing an FPS game and I made a pistol model In Blender that its split in 3 different parts so I put them into an empty object but when I look up and down the pistol gets out of my vision but I want to see it regardless of where am looking. This is my "Looking" script:
public float mouseSensitivity = 100;
public Transform PlayerBud;
public Transform cam;
public Transform wepon;
private float xRotation = 0;
// Start is called before the first frame update
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void Update()
{
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90, 90);
transform.localRotation = Quaternion.Euler(xRotation, 0, 0);
wepon.rotation = cam.rotation;
PlayerBud.Rotate(Vector3.up * mouseX);
}
As you can see I set me weapon.rotation equal to my camera.rotation and it does work but when I look up (80 -90 degrees up) my pistol disappears instead of pointing up. I would appreciate if you can help me whit this :)
Comment