public void SetByHandPosition(Hand hand) { Vector3 handPos = hand.ColliderPosition; float handDistance = (handPos - handle.position).magnitude; if (handDistance > doorGrabDistance && BreakAtLongDistance) { hand.Uninteract(); ReleaseDoor(); return; } lastEulerAngles = transform.eulerAngles; Vector3 initialRot = transform.eulerAngles; Vector3 direction = transform.position - handPos; direction.y = 0; Quaternion rawRotation = Quaternion.LookRotation(direction, Vector3.up); float newAngle = rawRotation.eulerAngles.y + angleOffset; float deltaAngle = newAngle - Angle; float clampedAngle = AngleLock.ClampAngleDeg(Angle, startAngle, startAngle + maxAngle, deltaAngle); transform.eulerAngles = new Vector3(transform.eulerAngles.x, clampedAngle, transform.eulerAngles.z); }
public void TestMinusFortyFiveToFortyFiveNoClamp() { float left = -45; float right = 45; Assert.AreEqual(AngleLock.TrimAngleDeg(left + 1), AngleLock.ClampAngleDeg(left, left, right, 1), "Angle is clamped to left "); Assert.AreEqual(right - 1, AngleLock.ClampAngleDeg(right, left, right, -1), "Angle is clamped to right"); }
public void TestZeroToNinetyNoClamp() { float left = 0; float right = 90; Assert.AreEqual(left + 1, AngleLock.ClampAngleDeg(left, left, right, 1), "Angle is clamped to left "); Assert.AreEqual(right - 1, AngleLock.ClampAngleDeg(right, left, right, -1), "Angle is clamped to right"); }
private void RotateDoor() { float rotateAngle = AngleSpeed * Time.deltaTime; rotateAngle *= flipMomentum ? -1 : 1; float clampedAngle = AngleLock.ClampAngleDeg(Angle, startAngle, startAngle + maxAngle, rotateAngle); transform.eulerAngles = new Vector3(transform.eulerAngles.x, clampedAngle, transform.eulerAngles.z); }
public void TestMinusFortyFiveToFortyFiveClampRight() { float left = -45; float right = 45; float divider = AngleLock.TrimAngleDeg((left + right) / 2 + 180); Assert.AreEqual(right, AngleLock.ClampAngleDeg(right, left, right), "Angle is not clamped to right"); Assert.AreEqual(right, AngleLock.ClampAngleDeg(right, left, right, 1), "Angle is not clamped to right"); Assert.AreEqual(right, AngleLock.ClampAngleDeg(divider, left, right, -1), "Angle is not clamped to right"); }
public void TestZeroToNinetyClampRight() { float left = 0; float right = 90; float divider = AngleLock.TrimAngleDeg((left + right) / 2 + 180); Assert.AreEqual(right, AngleLock.ClampAngleDeg(right, left, right), "Angle is not clamped to right"); Assert.AreEqual(right, AngleLock.ClampAngleDeg(right, left, right, 1), "Angle is not clamped to right"); Assert.AreEqual(right, AngleLock.ClampAngleDeg(divider, left, right, -1), "Angle is not clamped to right"); }