Mouse look script error.

Hay so i made a C# script that will allow me to look around a character in 3rd person here it is-

using UnityEngine;
using System.Collections;

public class Orbit : MonoBehaviour {
	
	public float turnSpeed = 4.0f;
	public Transform player;
	
	public float height = 1f;
	public float distance = 2f;

	private Vector3 offsetX;
	private Vector3 offsetY;
	
	void Start () {

		offsetX = new Vector3 (0, height, distance);
		offsetY = new Vector3 (0, 0, distance);
	}
	
	void LateUpdate(){
		offsetX = Quaternion.AngleAxis (Input.GetAxis("Mouse X") * turnSpeed, Vector3.up) * offsetX;
		offsetY = Quaternion.AngleAxis (Input.GetAxis("Mouse Y") * turnSpeed, Vector3.right) * offsetY;
		transform.position = player.position + offsetY; 
		transform.position = player.position + offsetX; 
		transform.LookAt(player.position);

	}
}

But theres an issue. I can only look left to right or if i change the code then i can only look up or down. If you look near the bottom where it says

		transform.position = player.position + offsetY; 
		transform.position = player.position + offsetX; 

If i have it like this then it will only move left to right but if i make it like this

		transform.position = player.position + offsetX; 
		transform.position = player.position + offsetY; 

Then it will only go up and down any help?

Found it!

instead of using conflicting equations,

transform.position = player.position + offsetY; 
transform.position = player.position + offsetX; 

use

 transform.position = new Vector3 (player.position + offsetX, player.position + offsetY, transform.position.z);

Right Vector3 takes 3 points.

player.position is 3 points X Y and Z

instead of this:

transform.position = new Vector3 (player.position + offsetX, player.position + offsetY, transform.position.z);

try this

transform.position = new Vector3 (player.position.x + offsetX, player.position.y + offsetY, transform.position.z);

Hey @awplays49 and @ZXYNINE it’s late (where I am) and we’ve all had a drink (OK I’ve had a drink!) but let’s not fight, click thumbs up if any of the previous comments were close to a solution and clicked answered if it fixes it.

EDIT:

That drink didn’t help my deductive reasoning but nice to see in cold light of day I still had some diplomatic skills!

Anyway try this:

using UnityEngine;
using System.Collections;

public class Orbit : MonoBehaviour {
	
	public float turnSpeed = 4.0f;
	public Transform player;
	
	public float height = 2f;
	public float distance = 3f;
	
	private Vector3 offsetX;
	private Vector3 offsetY;
	
	void Start () {
		
		offsetX = new Vector3 (0, height, distance);
		offsetY = new Vector3 (0, 0, distance);
	}

	void Update()
	{
		if(player == null)
			player = GameObject.FindGameObjectWithTag("Player").transform;
	}
	
	void LateUpdate()
	{
		offsetX = Quaternion.AngleAxis (Input.GetAxis("Mouse X") * turnSpeed, Vector3.up) * offsetX;
		offsetY = Quaternion.AngleAxis (Input.GetAxis("Mouse Y") * turnSpeed, Vector3.right) * offsetY;
		transform.position = player.position + offsetX + offsetY; 
		transform.LookAt(player.position);
	}
}

oh and @awplays49 it was and i can send you a picture