- Home /
How can I disable my player movement and camera movement when I hit I to open my inventory?
I want to stop the player from being able to move, and disable my third person camera from moving when I press I to open my inventory and then re-enable it when I press I again to close my inventory. How can I achieve this?
Answer by MSavioti · Feb 26, 2019 at 03:50 AM
Use a boolean variable that it's always checked before the movement operation starts. Then, change it to false when you don't want a certain something moving, like when you open your inventory.
Answer by Axtrainz · Feb 26, 2019 at 04:33 PM
You do what @MSavioti said, but there's also a thing for all rigid-bodies Freeze. To access it, you call the enum Constraint as below:
MyRigidbody.constraints = ...
Now to freeze your object movement, rotation, etc. you just call this way.
MyRigidbody.constraints = RigidbodyConstraints.FreezeAll;
//You can also call separated like below...
MyRigidbody.constraints = RigidbodyConstraints.FreezeRotationZ | RigidbodyConstraints.FreezePositionY | RigidbodyConstraints.FreezePositionZ;
To unfreeze the constraints and get back to normal set it to None
MyRigidbody.constraints = RigidbodyConstraints.None;
As per the logic of when to set that, I'll leave it to you.
Regards.
Your answer
![](https://koobas.hobune.stream/wayback/20220612192504im_/https://answers.unity.com/themes/thub/images/avi.jpg)