- Home /
Camera Tracks player not in the middle
Hey guys. I`m making a copycat of flappy bird called jumpy chicken and now I got a little problem, because I`m not a great coder. I want to let the main camera track the bird and I also made a little script for that which worked, but I don`t want that the camera tracks him in the middle, but a little bit more in front (Just like by the original flappy bird). I know I need to change the x position of the camera, but how? My script:
Transform Player;
float offsetX;
// Use this for initialization
void Start () {
GameObject player_go = GameObject.FindGameObjectWithTag ("Player");
if (player_go == null) {
Debug.LogError("Couldn`t find an object with tag `Player` !");
return;
}
Player = player_go.transform;
offsetX = Player.position.x - Player.position.x;
}
// Update is called once per frame
void Update () {
if (Player != null) {
Vector3 pos = transform.position;
pos.x = Player.position.x + offsetX;
transform.position = pos;
}
}
Help would be appreciated ;)
Answer by JasonSic · Apr 15, 2016 at 12:22 AM
Your problem is on line 16. You are subtracting the player's X position from itself which makes the offset 0.
Is this what you meant to do? offsetX = transform.position.x - Player.position.x;
yap this was what I meant to do. Thank you very much :) it worked how I wished!
Your answer
Follow this Question
Related Questions
Camera Problem 1 Answer
Unity 2D Position Issues 0 Answers
Player rotates with camera(face same direction as the camera) 1 Answer