Y
Y
Yaonosos2019-11-07 02:48:52
C++ / C#
Yaonosos, 2019-11-07 02:48:52

How to prevent camera movement in unity along the x-axis?

I'm developing a 2D game and I need the camera to not move on the X axis, only up, on the Y axis.
How can I do this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dollar, 2019-11-07
@yaonosos

Watch how she moves.
If it is attached, then you just need to change this coordinate every frame to what you need. Let's say, calculate what the relative displacement should be, given the position of the player in the world.

void LateUpdate() {
  float x = ...........; // вычисляете, на что сменить.
  transform.position = new Vector3(x, transform.position.y, transform.position.z);
}

If your camera is moved stupidly manually (in Update), then also manually DO NOT move it along X. That is, instead of the function from the player's X coordinate, substitute transform.position.x (that is, the same coordinate).

N
Niriter Inc., 2019-11-07
@niriter

tyts

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question