# Snap to Z (put a box on top of another)

Hi there, I’m making a drag and drop puzzle and I need some light on how to do this: I did a drag and drop mechanics follwiong this tutorial

and now I have a movable box, I need some way to snap this box to Z when I dragging it and it finds another box on the way. I know it’s pretty easy but I’m not having the right idea. any help please?
I tried make this work on 2 ways, the first, I get the Z of the mouse hit location, but then the box keeps updating the z value and keeps coming closer to the pawn/ camera

the second, I get the Z from where the player controler is pointing

but then, the box keeps floating intead of being snaped to the ground, and the second box doesn’t get on top of the first one

I tried some math formulas using the 2 Z values, but the results I get is the same result of the first image (the box keeps updating the Z value), or then, I can get a box on top of another, but with space between them.

Could you solve your problem by having a small collision volume on top of every box that detects a box entering and therefor snaps to it’s position?

I’ll try this but I din’t think it wikk wirk, I thought making a invisible grid on the top of the box could solve my problem, but then I still will not get to make the box go on the top of the other, I think, but I’ll try this

I’m trying to get the colision but I don’t know how to effectivelly do this, because sometimes I’ll put the box on the floor and sometimes one on top of another, could you show me some blueprint exemples?

Try doing a line trace from your box down on the Z axis. Break the Hit Result and get the hit location, then set the boxes location to the hit location. You’ll have to play around with the numbers to get an exact result but this should work for what you are trying to do.

Sorry for asking this, but could you please show me a blueprint exemple of this working? I’m trying to follow some exemples as seen in here:
https://docs.unrealengine.com/latest/INT/Gameplay/HowTo/UseRaycasts/Blueprints/index.html
But I can’t get this thing working

In case you’re still looking for a solution, I’ve just answered a similar question to yours: How make option in blueprint actor to "snap" static mesh component to floor? - Asset Creation - Epic Developer Community Forums