How do i randomly spawn objects between 2 CFrames or if there is a easier way?
✓ ANSWER ACCEPTED
How do i spawn objects randomly between 2 CFrames?
1 answer
✓ Accepted answer
I assume you mean on the line segment between the two CFrames' position. In this case, it's as simple as:
local start = cf1.p
local finish = cf2.p
local displacement = finish - start
local point = start + displacement*math.random()
Try to visualize the math in your head. As game developers we think of vectors as arrows in space. They can also be thought of as points.
In this case,
startandfinishare two points corresponding to your CFrames' position; anddisplacementis an arrow that starts from one of the points and reaches the other.
Now, to get a new, random point between these two points we simply stretch that displacement vector by a random factor comprised between 0 and 1. We can think of this number as a percentage of the distance between our two points.
We then add this new stretched displacement vector back to the first point to get our new random point.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
thanks :)