Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class VArithmetics
  6. {
  7.  
  8.  
  9. public static float GetDistance(Vector2 v1, Vector2 v2)
  10. {
  11. //Anger distance mellan Asteroide/rna och raketen
  12. Vector2 D = v2 - v1;
  13.  
  14. float m = Mathf.Sqrt((D.x * D.x) + (D.y * D.y));
  15.  
  16. return m;
  17. }
  18. public static Vector2 GetVelocity(Vector2 v1, Vector2 v2, float speed)
  19. {
  20. Vector2 direction = GetDirection(v1, v2);
  21. Vector2 unitDirection = GetNormalized(direction);
  22. return unitDirection * speed;
  23. }
  24. public static Vector2 GetNormalized(Vector2 v)
  25. {
  26.  
  27. Vector2 normV = v / Mathf.Sqrt((v.x * v.x) + (v.y * v.y));
  28. return normV;
  29. }
  30.  
  31.  
  32. public static Vector2 GetDirection(Vector2 v1, Vector2 v2)
  33. {
  34. Vector2 d = v2 - v1;
  35.  
  36. return d;
  37. }
  38.  
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement