Reputation: 97
VR-oriented game in dev. I have the two-hand-manipulation-script from the MRTK implemented, interacting with my objects works. Goal is to let the objects remain static in their position after interacting - theoretically working. As soon as I add collision with my environment (rigidbody @ interactableGameObjects). But as soon as I start interacting with them and let them actively collide with one of the scenery objects, they start tilting and floating without being willing to stop.
So I'm looking for an easy and not resource hungry way to stop any movement (translation, rotation) of my object after interacting with it - without adding gravity to it. My main concern is not how to stop all the motion, as I could freeze all constraints of the objects rigidbody or set the Rigidbodys Velocity and angularVelocity = 0.
So my basic idea: "if(movement != 0), and if(object != grabbed), then trigger movement = freeze." Haven't figured out, how to trigger this kind of event and how to check if item is grabbed or not. Or is there maybe an even easier way?
Thanks for any help!
Note: even if you take the sample scene of the twohandedmanipulation and add ridigbodys to the components, they start floating away without any interaction.
Tried so far: Putting sample scene in same conditions
Expect vs result: Floating away objects instead of remain fixed in space.
Upvotes: 0
Views: 77
Reputation: 4343
You can use RigidbodyConstraints to freeze the object's position and rotation while retaining the collision properties.
GetComponenet<Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
and to unfreeze:
GetComponenet<Rigidbody>().constraints = RigidbodyConstraints.none;
Upvotes: 1