- Home /
Question by
assasin512 · May 03, 2017 at 06:34 AM ·
camera-movement
How can I make my camera immovable on the Y axis?
I am a newbie to Unity and I was trying to make somewhat of an infinite runner to improve my stance. It's a game where a ball tries to stay on platforms. I made a camera follow script (c#) and I not sure how to stop the camera from following the ball when it falls of the platforms.
public GameObject player;
private Vector3 offset;
void Start()
{
offset = transform.position - player.transform.position;
}
void Update()
{
transform.position = player.transform.position + offset;
}
}
Comment
Use a vector that only follows the player's x and z axis. That way, the camera will stay in the same position when the player falls straight down.
void Update()
{
transform.position = new Vector3(player.transform.position.x + offset.x , 0 + offset.y ,player.transform.position.z + offset.z) ;
}
Best Answer
Answer by Bilelmnasser · May 03, 2017 at 06:47 AM
Vector3 pos= player.transform.position + offset;
transform.position=new Vector3(pos.x,transform.position.y,pos.z);
Your answer
Follow this Question
Related Questions
camera movements very slow, why!? :) 2 Answers
How can you make a FPS controller camera "fly"? 1 Answer
Mouse Camera Control 0 Answers
Teleporting a camera to a camera 1 Answer
Camera 2D Movement android unity 1 Answer