I need to follow a gameobject, only on the y axis. I have tried multiple other soloutions, none of which worked for my purpose.
Here is the outline of what I want to to do:
Rotate Left/Right with Q/E Respectively;
Stay at a set offset distance away from the player.
Smoothly rotate in a circle around the player.
Here is my current code:`using UnityEngine;
using System.Collections;
public class CameraBehaviourScript : MonoBehaviour
{
public GameObject Player;
private Vector3 offset;
Your method is fine, you’re just using the wrong values. Rotations are not stored as (x rotation, y rotation, z rotation). They are stored as Quaternions, so trying to take just the y component to keep the y axis rotation will not give the expected result. Instead, Quaternions have a EulerAngles method, which is used to get the Euler rotation (that is, (x,y,z) rotation), rather than the Quaternion values. By taking the y component of the Euler angles only, you can ensure that it remains fixed on the other two axes.
As to your other question, no, you can’t set only one component of the rotation. Not only would you again be setting the Quaternion value directly (which as I explained is a bad idea), but Unity uses properties to reference its fields, in order to return a copy of the data. Modifying that is nonsensical, as it isn’t really stored anywhere (except temporarily), and as it’s a copy of the original data, wouldn’t change anything anyway.
Use the smooth look at script from Unity, or even the third person controller has a script for the camera, allowing you to adjust height and distance from the character, as well as other various properties.
There are also a number of scripts here that may be useful (including a smoothfollow c# version)
You really don’t need all of this , To make the camera follow a player you make the camera the gameobject’s child . This should also work for the rotation