How can i move my camera forward independent of its pitch?
I cannot work out for the life of me how to do this.. The player is allowed to angle the camera, however, i want the camera to exist on a fixed Y axis, as such only the X & Z parts of the vector will change and Y will remain constant.
My only issue is is that if i use transform.forward
it will always change the Y axis if the camera is pitched, and if i use transform.forward
and set the end results y value to the fixed level i want, the speed of the camera is directly affected by the pitch and i want it to be completely independant, constant Y constant movement speed camera, how would i do this? Can i not use transform.forward
?
Answer by TreyH · Feb 13, 2016 at 12:26 AM
Easily: If you're using this to move the camera in a forward direction along the y-axis,
// Get the forward vector along a constrained Y-Space
Vector3 ConstrainedForward(Transform focus)
{
// Get the natural forward transition
Vector3 naturalForward = focus.forward;
// Nullify its y-component
naturalForward.y = 0;
// Normalize xz-plane and align it with the chosen y-axis
Vector3 fixedForward = naturalForward.normalized;
// This gives us a vector whose xz-planar speed is normalized
// while preserving the fixed Y component
return fixedForward;
}