コード例 #1
0
        // always returns with normalized length
        public static Vector2 Slerp(Vector2 fromV, Vector2 toV, float t) {

            // oh god this little knot has so many hidden trig and sqrts.
            var fromAng = fromV.Angle2D();
            var toAng = toV.Angle2D();
            float angleDelta = toAng - fromAng;

            // make sure we're taking the shortest route
            float flipper = angleDelta < 0f ? 360f : -360f;
            float maybeFlip = Mathf.Abs(angleDelta) > 180f ? flipper : 0f;
            float shortestDelta = angleDelta + maybeFlip;

            float angleToMove = shortestDelta * t;
            var newDir = fromV.RotateBy2D(angleToMove).normalized;
            return newDir;
        }
コード例 #2
0
ファイル: DebugPlus.cs プロジェクト: bdjewkes/trollplayer
        public static void DrawCapsule(Vector2 start, float radius, Vector2 dir, Color color, int numSegments = 20, float time = 0) {
            var angle = dir.Angle2D();
            DrawArc(start, radius, angle + 90, angle + 270, color, numSegments, time);
            DrawArc(start + dir, radius, angle + 90, angle - 90, color, numSegments, time);

            var leftDisplacement = dir.Left2D().normalized * radius;
            Debug.DrawLine(start + leftDisplacement, start + dir + leftDisplacement, color, time);
            Debug.DrawLine(start - leftDisplacement, start + dir - leftDisplacement, color, time);
        }