Grid Placement for Blocks/Objects

Hello, I followed a tutorial from Ryan Laley on YouTube that would allow players to place blocks in the world in a grid. However, this has developed a problem for me as I have a “machine” that I would like to place in the world however the piece is bigger than the 1 meter by 1 meter grid, so I would like it to use 2 meters by 2 meters.

Also, with the different things that I would like to add, I would like them to be on top of the block they are being placed on. The picture attached shows what I’m talking about where the machine Im wanting to place is halfway in the block placed on the ground.

Now I assume this is due to the center of the machine, but how do I fix this, and get the 2x2 grid working?

Hi man ,
Check your car blueprint,
if you open the blueprint you should place the car centered with the origin of the blueprint world.
If you are not sure , post a screenshot

About your grid:
i really am not sure, as you can see in this screenshot
To place the object in the center of the grid, you can just add 0.5 to the location.

Hello, I dont really know what you mean by car bp as I dont have a car in my level?

I can take a look and see about the offset and might have to change the location as when you pick up the item, it is put in “your hands” and when you left click a “hologram” is shown of where it will be placed (its just the actor with a transparent material), then when you left click it “places it”.

Sorry man, i have read “machine” and istantly translated in “car”

so you have an actor , and this actor , have inside a static mesh component , where this is placed exaactly?
Can you place 1 object 1x1 and one object greater to show the difference?

I do a linetrace when the player left clicks while holding an item, this linetrace checks if the player is looking at the ground or at the air, some more stuff later and then the linetrace hits the floor getting a location that the actor is set to. In the attached photo I have a 2x2 which is where I would like the brown machine to be centered on, and then a 1x1 block on the right. The machine in the middle is on/in a block right now.

Haven’t seen Ryan’s tut so not sure exactly how he is using the grid, you could just use the line trace hit, and use the actor or mesh component data to locate top center of the foundation mesh

This might work and I do have another solution Im gonna try, however, you seem to get the top center of the mesh, I would like to get the bottom center.

change the multiplier to -50, will give the bottom of the mesh.

( the above was for getting the center of the already placed foundation, then you would adjust placement of engine snapping to center with z offset based on engine scale/height)
If the grid setup already gives placement centers it would be even easier.

line trace hit results and vector math could be used to provide all info required negating the need for collision volumes and grids, probably over kill as the majority of your logic should only be active during item placement, but an interesting though exercise, I build a ledge climbing system based on 1 line trace and vector math, only active during jumping, with no collisions or arrow markers required :slight_smile: Calculations require less overhead vs collision volumes.

Well, I use the vector snapped to grid which I set to 100 (1m) so when I move the mouse the block snaps to the grid.

In the video here https://streamable.com/fhl3v1 , you can see that when you pick it up and then left click, it moves the “hologram” which is just the block with an opaque material to the placing location. Then when you left click again, it places it changing the material back to normal.

In the attached picture is the code that actually gets the location for the block placement. When you left click the first linetrace executes and checks if you are aiming at the ground, if you are, then the true branch executes doing a linetrace that gets the location of the reticle and sets the block to that location, with grid snapping in mind. However if the 1st linetrace doesn’t hit anything it does linetrace #3 which goes down 500 units until it hit the ground then gets that linetrace and location and does the same thing where it sets the block to the hit location.

Now, I could add an offset depending on the current item being held and offset it .5m on the x and y plane so that it is center on a 2x2 grid, however this would be too tedious, so I feel there has to be an easier way.

First define desired result, which in this case, placing the engine on top of the foundation block, do you want it centered or restricted to not overlapping an edge or ability to place 4 on a foundation?

At the moment foundation blocks are snapping to grid, if the engine mesh is centered correctly within the engine “actor” the X and Y should be fine, and only require an offset for the Z axis and a check to ensure the engine is above a foundation block and not floor or non-foundation block, this will result in engine placed in center.

If you require 4 engines per foundation, you have a few options, simplest would be to have 4 collision boxes dividing the foundation into desired locations, so if line trace hits one it will select that corner section for placement, really this should be using a custom trace channel, I’m compiling source code at the moment and computer is slow, later I might do a video explaining what I mean, I prefer Rusts free/restricted placement vs gridlocked style, so haven’t really used the grid option, would be good for specific game styles,

  1. The desired result would be for the machine actor to be centered (respectively to the x and y) in a 2x2 grid. But that is only for the machine as I would like other blocks or future actors to be placed in a 1x1 grid if they fit. I would also like the actor to be lifted so that it isn’t halfway in the block its standing on.

  2. What is Rust’s free/restricted placement vs gridlocked style your referring to? Is it Rust the game or something else?