Im trying to make a sprite in the background of my game follow my player (2D)

In my game I have a sprite in the background that I want to stay locked on to the middle of my camera when both my player and camera move. Im using cinamachine and CM vcam1 is currently following my player. I dont want the sprite to have the same Y position as my player since its in the air so I would need some sort of offset aswell.

For my understanding, you could add a UI canvas and then assign the sprite to a Image canvas game object. That way when your camera moves, the sprite would move with it. Kind of like a reticle in the center of the screen.

Ohhh ok Ill give it a go, ty!

if for some reason you need the sprite to be not a part of the UI, you could make it follow your players/cameras x position with that:

using UnityEngine;

public class FollowObj : MonoBehaviour
{
    public Transform targetObject;
    void Update()
    {
         transform.position = new Vector3(targetObject.position.x,
             transform.position.y, transform.position.z);
    }
}

if you attach this code to your sprite object and drag your camera or player into the targetObject value

1 Like

I’ll try both, I want the sprite to be behind some other objects in the back so this may work

It worked thanks!