- Home /
I cannot freeze both position on one axis together with rotation
Hello im creating a physics system in similarity of the penumbra/amnesia style (this means using the mouse to drag objects like boxes, and open doors with mousedrag.) When i drag heavy objects i only want to be able to drag it across the floor (because its heavy) so im trying to freeze both the Y-position and total rotation at the same time only enabling X and Z movement. Thing is when im using this lines of code at the same time, neither the position or rotation freeze work (they do separately though), can annyone enlighten me on whats going on here?
Lines of code:
rigid.constraints = RigidbodyConstraints.FreezePositionY;
rigid.constraints = RigidbodyConstraints.FreezeRotation;
Thanks!
"You can use the bitwise OR operator to combine multiple constraints"
It's the same thing you have to do to programmatically put objects on multiple layers.
http://www.codeproject.com/Articles/544990/Understand-how-bitwise-operators-work-Csharp-and-V
Sorry i dont have so much experience, but how come it isnt just possible with those two lines of code execute those two properties?
One overwrites the other. You need to combine them.
All constraints are stored in 1 variable, not 1 var for each constraint.
Answer by DoTA_KAMIKADzE · Apr 12, 2015 at 03:54 PM
Do like this instead:
rigid.constraints = RigidbodyConstraints.FreezePositionY | RigidbodyConstraints.FreezeRotation;
This^ is called a bitwise operation.
Thanks alot guys, it works perfect now and i also learned something interesting!