- Home /
Camera is not showing anything when following player
so i have a 2D game and there is a camera, and the player moves, the camera follows it with a script. so if the script is off, it shows all the terrain, but if i turn on the script, it only shows the colour background, and none of the terrain and not the player.
this is the script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class offsetFollow : MonoBehaviour
{
public Transform followTransform;
public Vector2 offset;
// Update is called once per frame
void FixedUpdate()
{
transform.position = new Vector2(followTransform.position.x + offset.x, followTransform.position.y + offset.y);
}
}
image of the camera settings (i just started making the game today, its a prototype)
and this is what the camera gives me in the game:
i checked the position of the camera in-game and it is following the player.
so what is the problem?
my OS: Windows 10 Unity version: 2020.3.13f1 my game is for Android
Answer by Anonymous620 · Jul 07, 2021 at 11:47 PM
You didn't add a z offset in your code, the camera will be at the same Z location as your player. You need to add a Z offset. Try this:
transform.position = new Vector3(followTransform.position.x + offset.x, followTransform.position.y + offset.y, followTransform.position.z - offset.z);
you will need to change your offset vector2 to vector3
Your answer

Follow this Question
Related Questions
2D Camera Smooth follow, FixedUpdate and LateUpdate odd difference, help needed. 1 Answer
Player character becomes shaky when camera is moving 0 Answers
2D Diablo style movement 1 Answer
How to Manually Move the Camera Horizontally or Vertically? (2D, Parallax), 0 Answers
Help with a 2d camera Controller 1 Answer