- Home /
Question by
Krockett · Aug 20, 2021 at 06:22 PM ·
rotationvector3eulerangles
How to limit the range of rotation of the world around my player.
Self taught and still learning. No prior coding experience * Currently I have the rotation of my world mapped to my mouse and on mouse button(0) press you can drag and rotate the work around your the player. The player is the center point of this rotation.
I am having a hard time trying to figuring out how to limit that rotation. Or even where to start. I dont expect anyone to write the code for me I just need to know where to look or what direction I should take.
This is what I have so far.
public float speed;
public Transform target;
public float sensitivity;
private Vector3 zAxisLeft = new Vector3(0, 0, 1);
private Vector3 zAxisRight = new Vector3(0, 0, -1);
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButton(0))
{
float rotateHorizontal = Input.GetAxis("Mouse X");
// float rotateVertical = Input.GetAxis("Mouse Y");
transform.RotateAround(target.transform.position, -Vector3.forward, rotateHorizontal * sensitivity);
}
}
}
Comment
Check out quaternions. https://docs.unity3d.com/ScriptReference/Quaternion.html And also you can use "Vector3.forward" for z axis.