Hi all, I’m trying to freeze my player (doesn’t jump, only moves) from moving left or right when it enters the Box Collider on top of the end platform. I got it set up on top of the end platform area, the OnTriggerEnter code is set up, and the “Is Trigger” box is checked. How do I use this code?
It took me a bit of playing around, but I discovered how to freeze a particular constraint on a rigidbody.
GetComponent().constraints = RigidbodyConstraints.(Whatever you want to freeze); works but it will maintain the rest of the other constraints to be free.
So if you wish to do multiple constraints, you have to use the | symbol. So for a single constraint in your case, GetComponent().constraints = RigidbodyConstraints.FreezePositionX; works.
If for multiple, then for example freezing both X and Y but keeping Z and all rotation free, would be GetComponent().constraints = RigidbodyConstraints.FreezePositionY|RigidbodyConstraints.FreezePositionX;