From tutorial: Camera rotates when making child of Player object.
Tutorial source: https://unity3d.com/learn/tutorials/projects/roll-a-ball/moving-the-player?playlist=17141
In the above tutorial, I was following everything word for word, but I seem to be getting different functionality then what's shown in the tutorial. I made a player object that moves on top of the ground object. I used the player script code given, and I made the Player object a parent of the Camera. The camera now follows the player object when moving on the x and z axis (which is good). The problem is, the camera now also follows the rotation of the player object!
Does anyone have a fix for that? I believe I followed the tutorial accurately...
I don't know about the tutorial, but the camera should have its own script that let's it follow a gameobject. if not childed to anything that will make sure, that's it is following and nothing else.
Answer by SpaceManDan · Aug 28, 2015 at 06:09 PM
Yes, you missed the part where you want to add the offset to the camera based on the players position.
Set player position in the inspector to x0 Y0.5 Z0 Set MainCamera position to X0, Y10, Z-10 Then add a C# script to the camera game object with the following code in it:
public GameObject player;
private Vector3 offset;
void Start()
{
offset = transform.position - player.transform.position;
}
void LateUpdate()
{
transform.position = player.transform.position + offset;
}
Save the script and then drag the player game object from the hierarchy into the public gameobject field that is blank in the inspector. If you did it right it should reference the player game object.