- Home /
Excluding Y axis rotation from a vector3 variable?
I have a character controller that is rotated by a vector3 variable using transform.up
However i need the Y axis rotation for controlling the character controller and using the vector3 variable directly transform.up = myvector3variable
interferes with the controls.
In this case, this appears as the character controller snapping back to its original Y-axis angle as soon as the input key for turning is released.
Use the example code i linked, as the results for my code and that are the same.
i originally used something very similar to the code in the link and i tried to fix it by doing this:
if( Input.Get$$anonymous$$ey( $$anonymous$$eyCode.(whateveriassignedhere) ) == true )
{
transform.Rotate( 0, rotationSpeed * Time.deltaTime, 0 );
}
and what the example in the link provided:
transform.Rotate(0, Input.GetAxis("Horizontal") * rotationSpeed, 0);
There is certainly nothing wrong with your code. Have just try it myself, in a test scene. $$anonymous$$ay some other bit of code mess things up, or you didnt set it up correctly. Please post more information.
$$anonymous$$ust be this part of the script that was originally made by SirGive
void Update () {
Physics.Raycast(backLeft.position + Vector3.up, Vector3.down, out lr);
Physics.Raycast(backRight.position + Vector3.up, Vector3.down, out rr);
Physics.Raycast(frontLeft.position + Vector3.up, Vector3.down, out lf);
Physics.Raycast(frontRight.position + Vector3.up, Vector3.down, out rf);
upDir = (Vector3.Cross(rr.point - Vector3.up, lr.point - Vector3.up) +
Vector3.Cross(lr.point - Vector3.up, lf.point - Vector3.up) +
Vector3.Cross(lf.point - Vector3.up, rf.point - Vector3.up) +
Vector3.Cross(rf.point - Vector3.up, rr.point - Vector3.up)
).normalized;
Debug.DrawRay(rr.point, Vector3.up);
Debug.DrawRay(lr.point, Vector3.up);
Debug.DrawRay(lf.point, Vector3.up);
Debug.DrawRay(rf.point, Vector3.up);
transform.up = upDir;
}
So maybe this is more of a question about how to neglect the Y rotation in transform.up
?
Im going to lock this and ask this as a separate question now that the reason for this was discovered.
Your answer

Follow this Question
Related Questions
Rotate Character Controller 1 Answer
Setting Up Vector and Still Rotating the Character 1 Answer
how to rotate my characters 1 Answer
rotate around character 1 Answer
Rotating Transform Evenly 1 Answer