- Home /
How can I combine these two rotations?
So I'm fairly new to unity and I'm trying to make a camera that can rotate around a player in all directions when right click is held, (Similar to roblox camera controls).
using UnityEngine;
using System.Collections;
public class Camera_Controls : MonoBehaviour
{
public float turnSpeed = 4.0f;
public Transform player;
private Vector3 offset;
private Vector3 offset2;
private Vector3 cameracontrols;
void Start()
{
offset = new Vector3(player.position.x, player.position.y + 2f, player.position.z + 9f);
offset2 = new Vector3(player.position.x, player.position.y+ 4f, player.position.z + 25f);
}
void LateUpdate()
{
if (Input.GetKey(KeyCode.Mouse1))
{
offset = Quaternion.AngleAxis(Input.GetAxisRaw("Mouse X") * turnSpeed, Vector3.up) * offset;
offset2 = Quaternion.AngleAxis(Input.GetAxisRaw("Mouse Y") * turnSpeed, Vector3.right) * offset2;
transform.position = cameracontrols + player.position;
cameracontrols = new Vector3(offset.x, offset2.y, offset.z);
transform.LookAt(player.position);
}
}
}
This is the code I have and it is not giving the desired result. What is the easiest way to make this work in the way I intended?
Comment
Your answer
Follow this Question
Related Questions
Rotate according to the camera on Y and Z only! 2 Answers
How to rotate an object on one axis facing another object? 0 Answers
UI not rotating correctly when in "Canvas mode - Camera", I'm hard stuck on this 0 Answers
I need help with TPS controls! 0 Answers
Is there a way to lock my camera's rotation and movement on certain axis? 2 Answers