Reworking Q and E for rotate Body
Hey guys,
I'm ready to ask for help. I've been trying to implement Q and E to rotate the player so that W, S, A, D move the body different directions with the base script. But something keeps snapping the rotation back to 0.
OLD CODE this forced the camera to move as well which doesn't make sense if your body is not attached.
New Code I figured would work by rotating the ForwardDirection object that I attached as the DirXform.
I'm ready to ask for help. I've been trying to implement Q and E to rotate the player so that W, S, A, D move the body different directions with the base script. But something keeps snapping the rotation back to 0.
OLD CODE this forced the camera to move as well which doesn't make sense if your body is not attached.
/* ZB
// reduce by half to avoid getting ill
if (Input.GetKey(KeyCode.Q))
YRotation -= rotateInfluence * 0.5f;
if (Input.GetKey(KeyCode.E))
YRotation += rotateInfluence * 0.5f;
*/ //ZB
New Code I figured would work by rotating the ForwardDirection object that I attached as the DirXform.
private float minimumY = -360F; //ZB
private float maximumY = 360F; //ZB
float rotateInfluence = DeltaTime * RotationAmount * RotationScaleMultiplier;
if (Input.GetKey(KeyCode.Q))
{
//Get the this and rotate it to the left so -= rotateInfluence * 0.5f;
float fYRot = transform.rotation.x - rotateInfluence * 0.5f;
fYRot = Mathf.Clamp (fYRot, minimumY, maximumY);
DirXform.transform.localEulerAngles = new Vector3(transform.localEulerAngles.x, fYRot, 0);
}
if (Input.GetKey(KeyCode.E))
{
// Get this and rotate it to the right so += rotateInfluence * 0.5f;
float fYRot = transform.rotation.x + rotateInfluence * 0.5f;
fYRot = Mathf.Clamp (fYRot, minimumY, maximumY);
DirXform.transform.localEulerAngles = new Vector3(transform.localEulerAngles.x, fYRot, 0);
}
