I followed a tutorial for a 3rd person camera setup. You can find it here (not sure if I can post links)
Long story short he sets up a follow system using an empty game object called “Camera Base” and then childs the camera to the game obj. He has another empty game object that is childed to our main character that is used in the script as an object for the camera base to follow. While both object’s(Camera Base and Main Camera) transforms are zeroed out he backs the CAMERA away from the character changing the CAMERA’S local transform but not the transform of the parent. The script is on the Camera Base and makes the Camera Base move toward the follow object on the character. The thing is the Main Camera and Camera base don’t move instantly towards the follow object like I would think it would. Instead it stays the desired amount back that we moved the camera to begin with. Only when the character moves does the camera react and follow. This is what I want to happen but is VERY confusing why it happens that way. If I zero out the camera base and main camera and move the CAMERA BASE backwards and run the script it would work how I think it would. The camera instantly moves toward the follow object and creates a sort of first person feel with the camera directly on top of the follow object.
I guess my question is why does this happen? Why does affecting the transform of the child(Main Camera) make it so our camera base never reaches our intended target but instead stays back a desired amount away from the character. Here is the code associated. It is a bit different from the tutorial as I am using touch controls instead of mouse for the rotation but the movement part is the same
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraControl : MonoBehaviour
{
public FixedTouchField TouchField;
public float CameraMoveSpeed = 120.0f;
public GameObject CameraFollowObj;
public float clampAngle = 80.0f;
public float inputSensitivity = 150.0f;
private float rotY = 0.0f;
private float rotX = 0.0f;
// Start is called before the first frame update
void Start()
{
Vector3 rot = transform.localRotation.eulerAngles;
rotY = rot.y;
rotX = rot.x;
}
// Update is called once per frame
void Update()
{
//ROTATION
rotY += TouchField.TouchDist.x * Time.deltaTime * inputSensitivity;
rotX += TouchField.TouchDist.y * Time.deltaTime * inputSensitivity;
rotX = Mathf.Clamp (rotX, -clampAngle, clampAngle);
Quaternion localRotation = Quaternion.Euler(rotX, rotY, 0.0f);
transform.rotation = localRotation;
}
void LateUpdate()
{
CameraUpdater();
}
void CameraUpdater()
{
//set obj target to follow
Transform target = CameraFollowObj.transform;
//move towards the game obj that is the target
float step = CameraMoveSpeed * Time.deltaTime;
transform.position = Vector3.MoveTowards(transform.position, target.position, step);
}
}