SteamVR and Unity Physics; How to make it work?

Over the last few days I’ve been attempting to make a simple table tennis game using SteamVR and the HTC Vive. The idea seems simple enough; add a paddle gameobject to the controller, add colliders to the paddle and ball and it should all work itself out. But it doesn’t, as the controllers are not Rigidbodies and their movement works separately from the Unity physics system. As such it creates issues like the paddle moving through the ball when the controller moves too quickly, or the velocity of the controller not mattering in the collision since its rigidbody’s velocity is always zero.

One thing I’ve tried is to mark the object as IsKinematic and to match its position to the controller using MovePosition and MoveRotation on the paddle Rigidbody. I also turned on interpolation to make sure moving the paddle too quickly doesn’t make it go through the ball. This sort of works, but with a huge delay; the paddle is always lagging way behind the controller - so this is not an option.

Another thing I’ve been trying is to implement my own physics code for the paddle, but in a way I feel like this shouldn’t be necessary as the controller already tracks all of the same variables as the ‘normal’ rigidbodies do, such as velocity etc. I’m wondering whether there is a possibility for some kind of ‘hybrid’ collision, where I could plug the SteamVR controller’s velocity, location etc. into the Unity Physics system.

Does anyone have any ideas on how I could approach this scenario?

As you’ve found, by making the paddle a child of controller object, its position is set by SteamVR and you don’t get accurate collisions, and unity physics either doesn’t work or works weirdly with it.

The simplest method I’ve found is to not make the paddle child of controller. Instead, keep the paddle separate as child of none, and join it with controller using a Fixed Joint with break force and torque kept to Infinity. This moves it using Unity physics engine and all physics interactions work perfectly!

For anyone who has the same problem; this article provides a very good solution which is included in a free downloadable library:

I had originally found a solution online that, instead of making the object a child of the controller, it kept it as a separate, non-kinematic object that tracked the position of the controller by dynamically changing the velocity so that it moved along with the controller. This worked, but the object was jerky, and lagged behind the controller. AntzyP suggests the better solution. Use a fixed joint. And you already have the code for this! Just check SteamVR_TestThrow.cs