- Home /
holding position
I'm working on a game where you jump from platform to platform, but each time the player jumps on one it flies away. I tried locking the position with the rigidbody, but for some reason when I press play, they all unselect except for z. rigidbody.freezeRotation = true; transform.rigidbody.constraints = RigidbodyConstraints.FreezePositionY; transform.rigidbody.constraints = RigidbodyConstraints.FreezePositionX; transform.rigidbody.constraints = RigidbodyConstraints.FreezePositionZ; This doesn't seem to work either. Any advice? P.S. There's going to be hundreds of platforms so manually programming the specific position for each one would not be possible.
there are 2 ways
you import character controller asset and learn how they did it
you do it your self by getting Transform.position and when you land on that you start adding the movement of that Transform.position to your transform.position
Answer by whydoidoit · Oct 18, 2013 at 11:24 PM
You want to do:
transform.rigidbody.constraints = RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionY | RigidbodyConstraints.FreezePositionZ;
Those are flags and you have to put them on together like that.
That freezes the rigidbody in every position by combining the constraints. The OP was trying to do them one at a time and so actually only froze the Z position.
So I did that, but then it started spinning so I added RigidbodyConstraints.FreezeRotationX|...Y|...Z and now my player just walks right through them as if they weren't even there. I added the class to a different cube. $$anonymous$$y player fell through it and got stuck
Your answer
Follow this Question
Related Questions
JS - How do I change the constraints of an object? 1 Answer
RigidbobyConstraints2D is not working in Unity 5.0.2f1 Personal Edition!! 0 Answers
Disabling rigidbody constraints in code - Freeze Position, Rotation etc 7 Answers
How do I query the RigidbodyConstraints? 3 Answers
Unfreeze Rigidbody ROTATION only 1 Answer