Hi Everyone,
I am trying to make my camera follow the main character until he collides with a gameObject.
So far everything works as expected, the camera follows the character, and I have a boolean that detects if the character collides with an object. But the camera doesn’t stop following the player when he hits something.
Here is my script:
public float addPos;
public Transform target;
private Vector3 targetPos;
void Update(){
targetPos = new Vector3(target.position.x + addPos, transform.position.y, transform.position.z);
}
void LateUpdate () {
if(gameObject.name == "Main Camera"){
if(!Astronaut.isDead){
transform.position = targetPos;
}else{
transform.position = transform.position;
}
}