- Home /
Simple script to follow player only shows the camera background
I am making a simple script to follow a character and and for some reason, when I enable the script, it only shows the background of the camera once active and nothing else. Everything renders fine without the script attached. Here's my the important parts of my implementation.
public Transform target;
void FixedUpdate () {
transform.position = new Vector3(target.position.x, target.position.y);
}
target
is set in the inspector to my player game object. Some other information to know is that I can still move my character and when I view the scene, the character is on the camera.
Answer by robertbu · Nov 09, 2014 at 04:55 PM
Change line 4 to:
transform.position = new Vector3(target.position.x, target.position.y, transform.position.z);
And this likely should be run in LateUpdate(), not FixedUpdate().
I changed my code to what you said and it still doesn't work . . . http://gfycat.com/ConsciousUntidyDinosaur
It is hard to see where the problem is without seeing the transform values of the camera both with and without the the script enabled. So either 1) edit your video, 2) provide the position and rotation values before and after enabling, or 3) put a package of your project on the net. I'll be able to quickly spot the problem if you provide #3.
Your line of code in your BasicCamera script does not match the line I gave you. Look carefully at the added third parameter. It is 'transform.position.z', not 'target.position.z'.
Your answer
Follow this Question
Related Questions
how to controll second camera (MiniMap)? 1 Answer
Problem with playmaker gui and "Get mouse button down" action. 1 Answer
Why is Input.mousePosition returning wired values using Cinemachine 2D with dynamic following? 0 Answers
Unassigned Reference Exception 4 Answers
Particle System On Key Press 2 Answers