Simple Vector Addition

//Note, we add Vector right into point, because we actually pretend that the time is 1 //and we know that, Distance(point) = Velocity(Vector)*Time(float); public class MeteorAttack : MonoBehaviour { public Vector velocity = new Vector(0.01667f,0); Point meteorPosition; // Use this for initialization void Start () { meteorPosition = new Point(transform.position.x, transform.position.y); } // Update is called once per frame void Update () { meteorPosition = meteorPosition.AddVector(velocity); transform.position = new Vector3(meteorPosition.x, meteorPosition.y); } } public class Point { public float x, y; public Point() { x = 0;y = 0; } public Point(float x,float y) { this.x = x; this.y = y; } public Point AddVector(Vector b) { Point c = new Point(); c.x = this.x + b.x; c.y = this.y + b.y; return c; } } [System.Serializable] public class Vector { public float x, y; public Vector() { x = 0; y = 0; } public Vector(float x, float y) { this.x = x; this.y = y; } }
This is originally meant for the Game Dev jordan magazine.
anyone who wants to use it, is free to do so, without any care in the world.
and any questions are welcome.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.