In Game Snapping with VR Motion Controllers?

Has anyone achieved in game snapping with motion controllers? Ideally this would be with sockets but could be to vertex or grid. I want to build with blocks like lego picking up pieces with the motion controller and then placing them approximately on other blocks which when in close proximity snap together. I have been following the threads on VR templates by @proteus and @mitchemmc which are both great. Proteus has developed socket snapping between hand/motion controllers and an object. What I am trying to achieve is between two objects which when placed in proximity snap together within the game.

Any help on this would be much appreciated…

Well you could model all of them with set sizes (ie: 1x1, 2x1) and when releasing snap them to the closest world position of the grid size. Or if working with specific areas of building (lego mat) have it get the closest “build area” and offset the grid by its position.

If you want blocks that aren’t perfect mutipliers of the grid (free form building) then sockets would probably be the best choice, you would just search for other actors within a snap radius, if one is found then find the closest two snap points and move the released object by the difference between the two locations.

There are a million ways to do it really, it depends on your particular end goal, it also isn’t a very hard problem to solve, you would probably be better off working through it by yourself and getting the exact result you want.

Thanks that’s really helpful. I will have a go - quite new to Blueprints. I pressume these functions would go in the individual objects blueprints. Would you only search when the objects dropped or continuously search for proximity to other sockets?

Well if you continually search you could have the closest snap point “glow” so that they know where it would snap too. It isn’t the most expensive task ever so it wouldn’t hurt you to do it every frame or on a pretty fast timer.

I tried making a building game a while ago.

I was aiming for a more “mechanical” building system, so I used physics constraints to attach each segment. The beams are instanced meshes, so their sizes are variable. To keep everything rotating smoothly, I set up it up so that while in “build mode”, the location and rotation of the beams are based on a system that divides the world location of the controller by 10, rounds it to an integer, and then multiplies it by 10. This process is done for each axis. The rotation was done by subtracting 45 degrees from each axis, and mapping each value from [0-360] to [0-4] then multiplying the result by 90. Each segment of the beam would shoot a line trace to every attach point and add a physics constraint to to any hit point.
Here’s the function I’m using to do the snap:

Hope this helps!

That’s great… really like the demo and like the incrament function. I need to do more research into attaching objects and physics constraints…do you use the attached to component function. In your example?

If you are going to be attaching a lot of things together you should “attach” not physics constraint.

For connecting the beams together I only used physics constraints by changing their locations and connected components whenever the beam is placed. I did use the attach to component function for grabbing the beams in “non-build mode”, which causes some issues with physics since the controller’s transform seems to be calculated before physics is (you can see it leading the rest of the structure).

Is this due to performance concerns? I’m pretty new to this stuff as well, but I managed to create hundreds to thousands of constrains without seeing a slowdown. I tried a few different attaching systems, but I found the physics constraints allowed a more dynamic connecting system (lack of parent-child hierarchies) unless I’m completely mistaken and I went about it incorrectly.

I think you’d run into issues the moment you tried to set any of them to simulate (or a lot of them). I assume you turn off simulation after placing, which with simulate off it doesn’t matter anyway as they won’t move.

I tried making a building game a while ago.

I was aiming for a more “mechanical” building system, so I used physics constraints to attach each segment. The beams are instanced meshes, so their sizes are variable. To keep everything rotating smoothly, I set up it up so that while in “build mode”, the location and rotation of the beams are based on a system that divides the world location of the controller by 10, rounds it to an integer, and then multiplies it by 10. This process is done for each axis. The rotation was done by subtracting 45 degrees from each axis, and mapping each value from [0-360] to [0-4] then multiplying the result by 90. Each segment of the beam would shoot a line trace to every attach point and add a physics constraint to to any hit point.
Here’s the function I’m using to do the snap:

Hope this helps!
[/QUOTE]

So I presume to get the incremental snap to work you are not attaching the beams to the controller but rather transforming them on a tick event?