Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class VArithmetics
- {
- public static float GetDistance(Vector2 v1, Vector2 v2)
- {
- //Anger distance mellan Asteroide/rna och raketen
- Vector2 D = v2 - v1;
- float m = Mathf.Sqrt((D.x * D.x) + (D.y * D.y));
- return m;
- }
- public static Vector2 GetVelocity(Vector2 v1, Vector2 v2, float speed)
- {
- Vector2 direction = GetDirection(v1, v2);
- Vector2 unitDirection = GetNormalized(direction);
- return unitDirection * speed;
- }
- public static Vector2 GetNormalized(Vector2 v)
- {
- Vector2 normV = v / Mathf.Sqrt((v.x * v.x) + (v.y * v.y));
- return normV;
- }
- public static Vector2 GetDirection(Vector2 v1, Vector2 v2)
- {
- Vector2 d = v2 - v1;
- return d;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement