Hi! I am trying to generate a random position using Vector3 that is x amount of studs away from a character’s HumanoidRootPart. Imagine these possible positions as the peripheral of the edge of a circle with a radius as x, where the center is the HumanoidRootPart’s position. I am only interested in the X- and Z-values of the Vector3, as the Y position is a constant. How would I code this?
hrp.Position + Vector3.new(math.random(-X,X),constantY,math.random(-Z,Z)) would do, fill in the values X and Z as the maximum distance away from the character. Also include the negative value of each so that the position can be in the opposite direction. For example, setting X and Z to 3 would result in each direction being anywhere from 0 to 3 studs away in either direction.
Yeah, but I want the distance between HRP and the position to remain constant (x)
You can probably use this code. It generates a random position on the circumference of the circle:
local angle = math.random() * 2 * math.pi local pos = CFrame.new(HRP.Position) * CFrame.Angles(0, angle, 0) * CFrame.new(0, 0, -x)