Plane that follow the player

Good evening mates,
I’m working on a side scroller game, and I’m using a plane with a material as backgound. I need that this plane follow the player through the level, so I attacked a script on it.
This is the main part of the script:

	void Update () { 
		if(!gameManager.isDead  !gameManager.endLevel){
			transform.position = new Vector3(playerTransform.position.x,transform.position.y,transform.position.z);
		}

	}

Everything works, but the problem is that this plane looks to be a bit laggy …
What I’m doing wrong ??

Thank you very much for the help :slight_smile:

There’s nothing wrong with your script.
In my opinion, that script seem overkill the purpose.
In update function, your script keep running, doing the logic (IF, !, ) and “new Vector3” all the time.
Think of the time and memory spend on it every frame.

Maybe think of different approach.
For example, try parent the “plane” to your player? (plane.transform.parent = player.transform)
Once the player dead / complete level, just remove the plane from parent.

Thank you very much shinichi88 !
When I parent the plane to the player the lag seems to be fixed, and I’ve also gained some fps :slight_smile: