private Vector3 InterpolateFacing(SnakeSegment segment, SnakeTrail.SnakePosition lastCorner, float interpolation) { Vector3 firstDirectionVector = lastCorner.UnitVectorToPreviousPosition * -1.0f; Direction firstDirection = SerpentConsts.GetDirectionForVector(firstDirectionVector); Direction secondDirection = segment.CurrentDirection; Vector3 firstEulerAngles = SerpentConsts.RotationVector3[(int)firstDirection]; Vector3 secondEulerAngles = SerpentConsts.RotationVector3[(int)secondDirection]; // Compare the sign of the angles and make sure they are both positive or both negative to account for the circle. if (firstEulerAngles.z * secondEulerAngles.z < 0.0f) { // sign problem to do with west (90) and south (-180) if (firstEulerAngles.z < -90.0f) { firstEulerAngles *= -1.0f; } else { secondEulerAngles *= -1.0f; } } Vector3 currentEulerAngles = firstEulerAngles * (1.0f - interpolation) + secondEulerAngles * interpolation; return(currentEulerAngles); }
private void SetSegmentRotation(SnakeSegment bodySegment, SnakePosition position) { Direction dir = SerpentConsts.GetDirectionForVector(position.UnitVectorToPreviousPosition); if (dir == Direction.None) { return; } Direction oppositeDir = SerpentConsts.OppositeDirection[(int)dir]; bodySegment.CurrentDirection = oppositeDir; }