The title might be misleading, but I am looking to get the coordinates of a part from within it. Basically, I have a script that does math.random and it chooses 2 positions randomly based on the position from the part. Most of the time, the coordinates that are chosen are outside of the part itself. How do I make it so that it only chooses coordinates within it? Thanks!
The answer is rather trivial simple!
Basically what you do is create a random cframe inside of a part, if it wasn’t modified.
Then you get the relative cframes and update the point’s cframe to the of the parts.
But how to subtract in CFrames?
Well you inverse them and then perform the add operator function like this.
local cf1 = ...
local cf2 = ... --random
local relativeCFtocf1 = cf1 * cf1:Inverse()
The parts that you see in the screenshot are supposed to be spawned only on the concrete road, not on the sidewalks, and not on the grass. There are 5 quarters that are for each street. It is chosen randomly each time a new part spawns. The problem is, that the parts still spawn outside of the specified region even after the quarter has been chosen. Please help!
EDIT:
This is the script for the random quarter selection with the position lines:
local part = workspace.Part
local rand = Vector3.new(
math.random(-100,100)/100 * part.Size.X/2, --math.random is now a capped value between -1 and 1, which is the multiplied by half the size of the Axis.
math.random(-100,100)/100 * part.Size.Y/2,
math.random(-100,100)/100 * part.Size.Z/2
)
local positionWithinPart = part.Position + rand;