0
\$\begingroup\$

Just getting started on a game project with SteamVR in Unity. I've run into an issue with the collisions though. The hands and the objects that can be held collide with everything in the scene as they should. But when an object is picked up, the hand and the object stop colliding with everything.

How would I go about fixing this? I could leave it as is, but if an object is let go of inside another, it gets flung out of the object it was inside.

The other odd behavior happens after you let an item go. The hand that was holding it continues to not collide with anything until you move the hand away. After that it'll collide with everything normally again.

\$\endgroup\$
1
0
\$\begingroup\$

It sounds like the colliders used in detecting hand-object intersection may be temporarily disabled whilst holding an object. This may be part of SteamVR's interaction script logic. I don't recall off the top of my head how the latest SteamVR rig operates; however, within the SteamVR rig hierarchy, I would take a look at the specific script components that react via OnTriggerEnter(), such as any "on grab" logic, and see how they act on colliders they reference. There should be a script API within SteamVR's rig package where you can register a listener to an "on grab" event. You can use this to troubleshoot, or enable/disable your own custom colliders used specifically to handle any further collisions on held objects. Ideally, studying SteamVR's API and interaction scripts will inform you about what happens to hand colliders OnTriggerEnter (they will likely have a Rigidbody component attached to them in the prefab hierarchy, likely set to be kinematic).

As for objects getting flung out from inside another: it sounds like both objects in question may be non-trigger colliders. Trigger colliders can pass through one another (assuming no additional script logic acts on them to do otherwise), whereas non-trigger colliders will separate upon impacting one another, preventing sustained intersection. A bouncy ball for instance can be realized with a rigidbody component using gravity and a non-trigger sphere collider, such that it bounces away from a non-trigger floor collider upon impact, producing an OnCollisionEnter() event. If the ball were a trigger collider instead, it would invoke an OnTriggerEnter() event upon passing through the floor collider, but it would continue falling through it.

In your case, it may be that a non-trigger collider is placed inside another via SteamVR's "object hold" interaction script, allowing for such placement during an object grab and hold (perhaps due to it disabling the object's collider component temporarily), but restoring non-trigger collision behaviour on the object upon its release, causing the released object to fly out.

\$\endgroup\$
1
  • \$\begingroup\$ Damn, thanks. This put me in the right direction. By default, the throwable script's attachment flags turned on the isKinematic option for the rigidbody when that item is picked up. I need to disable that, disable gravity on the object, and turn on velocity movement. Then in the scripts for the hands, it specifically waited to turn on collisions after dropping an object until it was clear of other colliders. Just had to tweak that. \$\endgroup\$ – DXHHH101 May 11 '20 at 14:52
0
\$\begingroup\$

The issue was that the hand colliders were getting disabled when an object was picked up, and would only re-enable when it completely left the area around original collider (Which wasn't working properly apparently). I tweaked it a little and now it works!

Fixed version here (HandPhysics.cs): https://pastebin.com/wXQvsLEY

\$\endgroup\$
3
  • 2
    \$\begingroup\$ In case the pastebin link ever rots, can you summarize the code changes you made here in the answer, so they're not lost for future readers? \$\endgroup\$ – DMGregory Jul 17 '20 at 0:53
  • \$\begingroup\$ Around line 90 in HandPhysics.cs, there is an if statement that checks whether an object is currently being held, and if it is, it disables the hand colliders. In the else, there is another if statement that checks if it's out of the way. I deleted everything inside THAT if statement and replaced it with "collisionsEnabled = true;". And around line 130 it turns off the hand colliders when the game pauses, I just got rid of that code. \$\endgroup\$ – Yurtle Jul 17 '20 at 23:00
  • 2
    \$\begingroup\$ Great — edit your answer to show these changes. \$\endgroup\$ – DMGregory Jul 17 '20 at 23:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.