#Dungeon Generation
1 messages · Page 1 of 1 (latest)
Is there a way I could have a detection for when an object is near a wall, and for things that are torches is there a way I could have it snap to a wall closest to the prop spawn point?
well, in this case, you just need to make sure that you don't pick a point that's too close to a wall
If a room is square, you can easily calculate a Bounds object that covers the floor
if you give each prop a radius, you can shrink the bounds by that much before randomly sampling a position
You can also use the physics system here. Use Physics.CheckBox to see if anything is in the way before spawning the prop
note that if you're just moved an object via a script, you may need to use Physics.SyncTransforms() before doing any more physics queries
or you'll be doing queries against an outdated view of the world
I use this kind of thing extensively in a procedural generation system I built for VRC worlds
(i also put trigger colliders near doors to prevent random clutter from blocking them)
Thank you very much
(to do this, you'll want to create a component to hold that data)
in my system, everything you can spawn has a SetupRoot on it
which includes that information (and runs other setup logic)
without physics you can really just set your index has walls already and check neighbor indicies
ex. tiles[0,1] northWall = true, eastWall = true, southWall = true, westWall = true.
so now when [0,2] is created it checks all neighbors, and since [0,1] in this case is north of it, it'll compare against its southWall and since it's true it won't create a new wall.
- some logic if you want to make a wall with door or not
My system is sort of set up like that each wall is made of of 3 game objects and the wall with the door on it has the door under it. Pretty much like a bunch of puzzle pieces
Looks kinda like this in the Hierarchy
Entrance - East
endWallLeft
wallEntrancedoorWall
doorOutline
Door
endWallRight