If we have two objects of Vector2
which represents 2 corners of a rectangle, a region:
Vector2 corner1 = new Vector2(-5, -5);
Vector2 corner2 = new Vector2(5, 5);
How can you generate a random position between these two vectors (any where in the rectangle it creates)?
What I thought to do is, the the distance from x1
and x2
and the same for y1
and y2
, and do a random value from that range.
But what if the first vector is 5, 5
and second vector is -5, -5
? I will have to add a negative distance, am I right?
Whats the most efficient way to do this?
Aucun commentaire:
Enregistrer un commentaire