How to prevent hands from passing through objects!

I would like to know if anyone can help me with a problem …

I have created buttons to press in vr and I would like my hands (controlled by Oculus controllers) to press the buttons without going through them so that the experience is more realistic.

How could I solve it?

Thanks to anyone who will be able to help me or even show me where to find information

This is pretty tricky given you cant stop a player’s controllers from passing thru your buttons in reality. But what you can do is separate the controllers from the hand meshes by putting false / visible hands in your pawn class and using the motion controller components as invisible targets to try and reach on Tick. When you go to set their world locations and rotation, check the Sweep box on - and that way when the fake hands collide with a surface they’ll stop on contact. When you pass down thru a table surface at an angle though (as an example), you’ll notice they get hung up weird if you try to translate position directly towards to your controllers location - instead of finding like the ‘closest possible’ location, which ruins the immersion a bit. So a trick that works a little better is to try and match the X first, then Y and then Z in three separate SetWorldLocation sweeps as a hacky way to get closer. You may also want to put a phys material on the hands that has no friction so they glide better too.

Then the next issue of course is what to do about the collision itself. If you’re using skeletal meshes with animations on the hands, the engine assumes skeletal meshes are characters and defaults to a simple collision cylinder centered at the root … which unfortunately on an oculus touch controller is just up a bit from the front trigger. That means you may collide with your button before the finger reaches it, meanwhile if you turn your hand around you’ll find the wrist will pass thru no prob. A pretty physics asset with sphyls on the bones all nice and tidy is no @#$ help because that’s only active for cloth sims and ragdolls. So you may want to add a box collision offset and shaped around your hands and use THAT for collision instead. I’d recommend a custom collision channel specifically for hand interactions too btw. Basically, this is all a nightmare heading your way and maybe only works for the most basic of prevention of hands going thru walls or tables etc.

What most VR games seem to do is capture an overlap event on the hands (or a finger maybe in your case) when a hand gets near something interactive, and that object basically takes over control of where in space that hand is registered. So maybe you could detect proximity to your button, then only allow the fake hands to approach on a normal vector in/out from the button face so the player can poke at it. You could use this event to adjust the anim from an open hand to a finger pointing pose too. If it hits the end of a clamped range all the way in - that becomes your press event. When the controller moves away from the button, you go back to seeking it as a target per normal and open the fingers up again. You’ll want quite a bit of space between buttons and also figure out what to do when the finger overlaps multiple buttons. Anyways, that might be your best route to a solution or at least hopefully give you some ideas to try.