Day 133 — Implementing Shooting for a 3rd Person Game

private void Rotation()
{
float mouseX = Input.GetAxis("Mouse X");
float mouseY = Input.GetAxis("Mouse Y"); Vector3 currentRotation = transform.localEulerAngles;
currentRotation.y += mouseX * _cameraSensitivity;
transform.localRotation = Quaternion.AngleAxis(currentRotation.y, Vector3.up);
Vector3 currentCameraRotation = _mainCamera.gameObject.transform.localEulerAngles;
currentCameraRotation.x -= mouseY * _cameraSensitivity;
currentCameraRotation.x = Mathf.Clamp(currentCameraRotation, 0, 26);

_mainCamera.gameObject.transform.localRotation = Quaternion.AngleAxis(currentCameraRotation.x, Vector3.right);
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Vector3 center = new Vector3(0.5f, 0.5f, 0);
Ray rayOrigin = Camera.main.ViewportPointToRay(center);
RaycastHit hitInfo;
if (Physics.Raycast(rayOrigin, out hitInfo))
{
Debug.Log("Hit: " + hitInfo.collider.name);
}
}
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store