Example #1
0
 public static Vector2 Projection(Vector2 target, Vector2 direction)
 {
     return Dot(target.Normalized(), direction) * target.Normalized();
 }
Example #2
0
 /// <summary>
 /// Returns a vector that is closer to target from current by an amount
 /// defined by step. If step is greater than distance, target is returned.
 /// </summary>
 /// <param name="current"></param>
 /// <param name="target"></param>
 /// <param name="step"></param>
 /// <returns></returns>
 public static Vector2 MoveStep(Vector2 current, Vector2 target, float step)
 {
     Vector2 tempVector = new Vector2(target - current);
     if (tempVector.magnitude > step)
         return (current + (tempVector.Normalized() * step)); // The distance is more than step, so return a point that is step amount closer to target than currenty
     else return target; // Return target to not overshoot (i.e. go past) the target when step was greater than the remaining distance
 }