How to fix this bug? Camera goes up by itself.
Hello! I have a problem that the camera goes up by itself. using UnityEngine;
public class NewBehaviourScript : MonoBehaviour { public Rigidbody rb; // Start is called before the first frame update
// Update is called once per frame
void FixedUpdate ()
{
rb.AddForce(0, 0, 1000 * Time.deltaTime);
}
}
Answer by streeetwalker · Apr 16, 2020 at 02:03 PM
@khabibyusupov2014, the question is, how do you want the camera behave?
Because a camera's viewing direction along it's local positive z axis, when you apply a force along that axis as your code is doing, the camera will move in along that axis.
Whether it moves up or down depends on the camera's viewing direction, whether or not the force is positive or negative (your code applies a positive force on z) and whether or not the camera is parented to some object that also has some rotation.
In sum, your code does not provide not enough information to tell if the camera is moving up or down and how to correct the problem.
You say it's moving up then, OK, apply a negative force along z instead to move it down, but we're just shooting in the dark. You don't tell us what you want the camera to do.
Your answer
![](https://koobas.hobune.stream/wayback/20220612231525im_/https://answers.unity.com/themes/thub/images/avi.jpg)