#Spawn A Part Within Radius Around Player, Only On-top Certain Part

1 messages · Page 1 of 1 (latest)

opal sparrow
#

I'm trying to spawn a part around the player within a radius, however only on the same part as the player (if standing on the edge, it cant spawn outside the part's region, like a part-masked radius)

I'm a little stumped trying to figure out how to do this and I've tried looking it up a good bit, but it seems a little specific

#

spawning part AROUND the player, but only within the bounds of the darker green block, I dont want to spawn ANYWHERE on the green block because I dont want it to be on the other side

mint pecan
opal sparrow
#

I already have the part reference, I'm just trying to spawn a part in a radius around the player, but make sure its within the region of that part

Can zoneplus do something like that? I havent looked into it before, and I dont know if I'd really want a whole new sort of zone module when I already got a system for my spawn zones going

mint pecan
#

when you have a spawn zone, the "spawn in radius around character within spawn zone" is the easy part

#

defining the spawn zone is the hard part of this

opal sparrow
#

would it not be like.. Part.Size.X/2 and Part.Size.Z/2 to get the.. well I guess that would end up being circular shaped

mint pecan
opal sparrow
#

I was thinking of magnitude in my head

mint pecan
#

circles are different

opal sparrow
#

how would you end up making something like this work? assuming you have the player position and the part as the defined zone

mint pecan
#

uniform distribution on a circle is also not as straight forward as it is for a box

opal sparrow
#

I only really need box

mint pecan
#

the boundaries of the spawn zone are how you limit the spawning radius to within the spawn zone only

#

you can use the part's x and z sizes to define the edges, but depending on what you want, i.e specifically in an area around the player instead of anywhere in the zone, you just need to refine the spawn zone that way

#

it's just vector math

#

bit of extra work tho if you want spawn zones that are not axis aligned (e.g rotated zone)

opal sparrow
mint pecan
#

vector math

opal sparrow
#

figured it out

local spawnPos = part.Position + Vector3.new(math.random(-part.Size.X/2, part.Size.X/2),0,math.random(-part.Size.Z/2, part.Size.Z/2))
local direction = (spawnPos - player.Character.HumanoidRootPart.Position).Unit
spawnPos = player.Character.HumanoidRootPart.Position + direction * math.random(6,20)```
#

well, actually the direction movement could push them outside the zone

#

so its not properly clamped

mint pecan
#

and yeah, it could push outside the zone

#

uniform distribution is a bit awkward with circles, even worse if you cut into the shape

#

best technique i can suggest for you if you want to keep the circle is to roll a random position repeatedly and reject the ones that fall outside the boundary. This is a real technique that is sometimes used for uniform distribution in odd shapes like this.

#

it's not pretty but you can have a working implementation pretty quickly and move onto other things

opal sparrow
hollow hemlockBOT
#

studio** You are now Level 3! **studio

opal sparrow
mint pecan
#

i don't think anyone is going to notice if the spawning happens in a square around the player instead of a circle

#

the math is a lot easier and you don't have to do the guess-until-valid-location thing

opal sparrow
#

idk how to keep it around the player but also a square and also within the bounds of the part

mint pecan
#

you then limit the bounds of the player's spawn zone to within the larger spawn zone

#

it's quite simply a game of keeping a smaller cube inside the bigger cube

opal sparrow
#

hmm, is there a way to do a sort of math.clamp kinda action?

mint pecan
#

yeah

#

it's just math.clamp

opal sparrow
#

okay well yeah but

#

💀

mint pecan
#

obviously you don't need a physical part for the player's spawn zone. just use math to define it

opal sparrow
#

only player X is leaving BaseSpawnZone, how do I clamp the PlayerSpawnZone X within the BaseSpawnZone region

mint pecan
#

math

opal sparrow
#

local spawnPos = part.Position + Vector3.new(math.random(-part.Size.X/2, part.Size.X/2),0,math.random(-part.Size.Z/2, part.Size.Z/2))

opal sparrow
mint pecan
#

yea its just math

opal sparrow
#

💀

#

no duh

mint pecan
opal sparrow
#

I dont know the exact math thing to do here? thats why im asking this question in the first place 😭

mint pecan
#

this may help you, specially the first section on pythag https://www.youtube.com/watch?v=DPfxjQ6sqrc

This video outlines what I believe are some of the core principles you need to understand to make dynamic computer games, covering vectors, angles and motion. I've tried to present it in such a way that highlights the relationships between these principles, so you can identify when to use one or the other, or combinations of them. It is by no me...

▶ Play video
opal sparrow
#

what sort of vector math, idk what I need to do still

#

I know vector math generally

mint pecan
#

you just said you don't know the exacts

#

manipulating boxes and cubes is the easiest part of learning vector math

opal sparrow
#

yeah im just asking how to clip a region to a certain region

mint pecan
#

operate on each component?

#

probably easiest to use a topleft,bottomright vector pair for 2 opposite corners, clamp both, and what's left is the spawn zone

#

otherwise you have to do weird stuff with pushing the center of the cube around

#

it's as simple as topleft=min(x1,x2),min(y1,y2) etc bottomright=max(x1,x2),max(y1,y2) etc

opal sparrow
#

I think the hard part in my head is clamping the actual spawn region hrp.Position + Vector3.new(math.random(-10,10),0,math.random(-10,10)) by the baseSpawnRegion part.Position + Vector3.new(math.random(-part.Size.X/2, part.Size.X/2),0,math.random(-part.Size.Z/2, part.Size.Z/2))

Would I just add a math.clamp(... but like, yeah I would sure but, im just confused on what im clamping by what, like the baseRegion variable will just give me a position within the region, and my playerRegion variable will just give me a position around my player, but then, do I clamp the... I just dont know where I'd put the clamp

#

math.clamp is for clamping a number within 2 other numbers, but im clamping... a vector3 position... by another vector3 position???

mint pecan
mint pecan
#

this is best way i can show you without giving you code as an answer. it's always better if you're able to solve on your own that's how you get real understanding