- Home /
2D Camera Problem
Hello friends, i have a code that camera is following the player. Its working fine but not exactly what i need. Its following the player and player is center of screen. I dont want to player is center of screen. Player should be more close to right or left of the screen. How can i do it? Here is the code.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class camera : MonoBehaviour { public GameObject car; public float cameraFollowSpeed = 2f; // Use this for initialization void Start () {
}
// Update is called once per frame
void Update () {
transform.position = Vector2.MoveTowards(
transform.position, car.transform.position,
Time.deltaTime*cameraFollowSpeed);
}
}
Answer by mustakbaba · Aug 24, 2018 at 01:21 PM
i fix that wit this code
transform.position = new Vector3( transform.position.x, car.transform.position.y+5, Time.deltaTime*cameraFollowSpeed); transform.position = Vector2.MoveTowards (transform.position, car.transform.position, Time.deltaTime * cameraFollowSpeed);
Your answer
Follow this Question
Related Questions
Unity 2D camera and lighting issues 2 Answers
How to handle camera rotation in a 2d multiplayer 0 Answers
Blur on first plane 0 Answers
Lock main camera on x-axis 2 Answers
2D Platformer Demo Camera Follow script doesn't follow player 1 Answer