Question by
RhinocerosGamesProduction · Dec 11, 2016 at 08:56 AM ·
rotationclampmouse input
Problem with Clamping Mous Y input
Hey! I want to rotate an Object around its x-Axis, for which I use the Mouse Y input. It's sort of a pacman body with two cubes where the "mouth" shall open. But i dont want to rotate it around, it has to stop at a certain angle. I got that so far but the problem is that when i keep my mousing moving up, the values will go to 1.0 and then back to -1.0 and again, back to 1.0. This makes the pacman mouth snap back pretty fast and it is then out of control. Here is how i tried to manage it:
void Turn()
{
if (Mathf.Abs(turnInputX) > 0)
rotationX *= Quaternion.AngleAxis(moveSettings.rotateVelocity * turnInputX * Time.deltaTime, Vector3.up);
if (Mathf.Abs(turnInputY) > 0)
{
float y = turnInputY;
rotationY *= Quaternion.AngleAxis(moveSettings.rotateVelocity * y * Time.deltaTime, Vector3.left);
}
// Clamp on maxAngle
UpperBody.rotation = transform.rotation * Quaternion.Euler(Mathf.Clamp(rotationY.x, minAngle, maxAngle) * Mathf.Rad2Deg, 0, 0) * standardRot;
transform.rotation = rotationX;
}
I hope you can help!
Comment