- Home /
Flythrough camera parallel to the terrain
Hello
I need a camera floating over the xz plane parallel to it. The following script is only half ok:
transform.position += transform.forward*moveSpeed*Input.GetAxis("Vertical");
transform.position += transform.right*moveSpeed*Input.GetAxis("Horizontal");
Because the vertical axis is directed parallel the cameras direction vector, thus it won't float over the plane but gets closer or farther to it, since the vector has an y component. Translating with (x, 0, z) changes the lookat angle. I think moving the origin of the cameras direction vector would solve the problem, but I don't know how to do it. Or in need to follow a completely different approach?
Try making a Physics.Raycast at the ground every step to find your altitude, and adjust accordingly! If it sounds like what you need, I can make a more complete answer in a bit when I have more time.
Answer by AlanChatham · Sep 22, 2011 at 07:19 AM
Instead of using transform.forward, could you calculate a new vector and use that? Something like:
var verticalDirection : Vector3 = transform.forward;
verticalDirection.Translate(transform.position.x,0,transform.position.z);
transform.position += verticalDirection*moveSpeed*Input.GetAxis("Vertical");
Your answer
Follow this Question
Related Questions
Free Camera 2 Answers
Third Person Camera Orbit 0 Answers
3rd person camera to player 2 Answers
Exclude Objects From FloatingOrigin 1 Answer