I would like to know how the block placement system works in lumber tycoon. I mean the way blocks are automatically placed in order to not collide with any other blocks. By this I mean when we select something to place and a shadow appears, what method should I use to decide where the shadow should appear.
I tried making my own version of it but it has plenty of issues when the block doesn’t have a perfect orientation or when 2 blocks are adjacent.
I tried looking on the internet or on the forums but nothing really talks about how blocks should be placed.
This is what I mean by where the shadow should go:
We can see that when my mouse is on the wall, the block that I am trying to place is placed on the wall rather than IN the wall. How do games like this calculate the offset needed to place the block correctly?
All of them are very basic and the only good tutorial that uses a grid system that I found didn’t have the feature for placing blocks on the side of others.
Thats where you come in, while yes it would he ideal if everything we needed was in a single YouTube video, but the truth is your going to need to Frankenstein together a bunch of code and make your own system
Through doing this you will understand how the code works and soon enough you will be able to lake it fully on ur own
I know I have to code it myself. I was just curious on the different methods I could use to achieve this. But I mean, you’re right, what I am asking for is very specific and the chances that I find someone that actually knows how is very slim.
This module is very helpful and polished but it still isn’t what I was specifically looking for. I will be looking into its code to inspire myself tho. Thank you
I actually found the easiest way to make a polished plot building system. The only limitations are blocks that have even sizes. So make sure all of your vector3 are made out of odd numbers.
I basically get the mouse position and the normal of the surface its touching, I then multiply that normal by half of the size of the hitbox of said object I am trying to place. This will give me the offset vector3 needed to push the block onto the surface of whatever wall your mouse is looking at. Simple as that!
Obviously there will be colliding if you put your mouse in the corner of a room since the function will only take into consideration the 1 surface your mouse is looking at but you can fix that by simply displaying the object as red since its an invalid position. After so you just have to connect remoteevents and security checks on the server before spawning the object serverside.