1
\$\begingroup\$

I'm working in Unity with SteamVR for a school project. I'm trying to have a chest that can be opened and shut. I tried using a hinge joint but it would break if the attached body was static which is what I want.

I'm now trying to use a circular drive which works better but the lid to the box will move away from the intended position when colliding with the body of the box which is set to static and kinematic.

I can fix this by setting the lid to kinematic but it won't collide with the body anymore. Both the lid and body are properly colliding with the hand and with a sphere I added to help test collisions.

I'm assuming the issue is that two kinematic objects can't collide with each other but I don't know how else to approach this.

\$\endgroup\$
1
  • \$\begingroup\$ How about adding joints between the chest and the floor instead of making it static? Bind all four corners to the floor and try it that way. Also, it might be viable to make the chest impossibly heavy but not static. \$\endgroup\$ – John Hamilton Dec 7 '20 at 7:35
1
\$\begingroup\$

There's two different parts to your chest: The bottom part and the top part which would open up like so enter image description here

One thing to understand is that 'static' objects are expected to never move throughout the scene e.g. a bridge, or a building

Sounds like in your case, the base of the chest would not move, so indeed it should be static, but if the top part can open, then it should not be static.

What about kinematic? From unity docs: If the object is kinematic, "Forces, collisions or joints will not affect the rigidbody anymore." i.e. you will not be able to grab onto the chest's top part and open it up. This means that the top part should not be kinematic either.

What about the actual implementation? I think you were on the right track adding hinge joints between the bottom and the top part of the chest. You'll probably need to tweak the values of hinge joints until you find what works for you. A good way to test if the hinge joints are working is to add the 'Constant Force' component onto the top part of the chest.

Constant Force

Once you know that the hinges are working, the next step would be to make the VR hands be able to grab the top part (either the whole thing or just a handle). Here what you could do is once the player's hand is close enough to the top part of the chest, if he grabs it, create a joint between the top part of the chest and the player's hand. Then the top part of the chest will follow the player's hand.

Here's a video that shows how to do that, except he's doing it with a door. Same concept applies to your chest though. https://www.youtube.com/watch?v=3cJ_uq1m-dg

\$\endgroup\$
1
  • \$\begingroup\$ the info you gave helped me understand a bit more about my problem so I thank you for that. unfortunately I had already seen the video you provided and didn't find it to be very helpful. when I followed the video I found that the lid wouldn't follow the hand properly and would still sometimes have trouble colliding with base. \$\endgroup\$ – tallbob99 Dec 11 '20 at 6:49
0
\$\begingroup\$

I decided the answer I was looking for was a lot simpler than I was making the challenge out to be. instead of actually needing the lid and the body to collide I just needed to make sure they never clipped through each other. the circular drive lets me set limits for how far the drive can rotate, I set the min angle to -90 and the max angle to 0, this way the lid cant go far enough to ever go through the body.

\$\endgroup\$

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.