help with a camera bug
when ever i look up it spazzes out and then the player controlls are backwards because the camera is backwards but i cant see whats wrong please help im new to coding C#
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerLook : MonoBehaviour { public Transform playerBody; public float mouseSensitivity;
float xAxisClamp = 0.0f;
void Awake()
{
Cursor.lockState = CursorLockMode.Locked;
}
void Update()
{
RotateCamera ();
}
void RotateCamera ()
{
float mouseX = Input.GetAxis ("Mouse X");
float mouseY = Input.GetAxis ("Mouse Y");
float rotAmountX = mouseX * mouseSensitivity;
float rotAmountY = mouseY * mouseSensitivity;
xAxisClamp -= rotAmountY;
Vector3 targetRotCam = transform.rotation.eulerAngles;
Vector3 targetRotBody = playerBody.rotation.eulerAngles;
targetRotCam.x -= rotAmountY;
targetRotCam.z = 0;
targetRotBody.y += rotAmountX;
if (xAxisClamp > 90)
{
xAxisClamp = targetRotCam.x = 90;
} else if (xAxisClamp < -90)
{
xAxisClamp = -90;
}
transform.rotation = Quaternion.Euler (targetRotCam);
playerBody.rotation = Quaternion.Euler (targetRotBody);
}
} ,Whenever i look up its spazzes out and then i walk backwards and i cant find anything wrong with the code CSHARP please help im new to coding
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerLook : MonoBehaviour { public Transform playerBody; public float mouseSensitivity;
float xAxisClamp = 0.0f;
void Awake()
{
Cursor.lockState = CursorLockMode.Locked;
}
void Update()
{
RotateCamera ();
}
void RotateCamera ()
{
float mouseX = Input.GetAxis ("Mouse X");
float mouseY = Input.GetAxis ("Mouse Y");
float rotAmountX = mouseX * mouseSensitivity;
float rotAmountY = mouseY * mouseSensitivity;
xAxisClamp -= rotAmountY;
Vector3 targetRotCam = transform.rotation.eulerAngles;
Vector3 targetRotBody = playerBody.rotation.eulerAngles;
targetRotCam.x -= rotAmountY;
targetRotCam.z = 0;
targetRotBody.y += rotAmountX;
if (xAxisClamp > 90)
{
xAxisClamp = targetRotCam.x = 90;
} else if (xAxisClamp < -90)
{
xAxisClamp = -90;
}
transform.rotation = Quaternion.Euler (targetRotCam);
playerBody.rotation = Quaternion.Euler (targetRotBody);
}
}
wow even this site has bugs ok then i hope you can actuall read this
Your answer
Follow this Question
Related Questions
I need help witha bug,Glitch While looking up 0 Answers
Nested class Lists inspector overlapping bug 1 Answer
RTS camera Controles 0 Answers
AnimationComplete() Error 0 Answers
Photon - Cannot join same room 1 Answer