- Home /
How to lock the players position by Z?
I want him to be able to move by X and Y but not by Z! I'm interesting in locking the players position
Is there any more elegant solution than something like this? :
void FixedUpdate()
{
transform.pozition.z = 0.0f;
}
Answer by etaxi341 · Jul 27, 2014 at 01:41 PM
I don't know any other solutions. I am always using this. Maybe you can use a Rigidbody. Rigidbodies have the possibility to lock one or more axis.
Answer by etaxi341 · Jul 27, 2014 at 01:36 PM
I am always making a Script that sets the Z-Position of the Player in a FixedUpdate to the Z position it started with
@etaxi341, that's perfect! Post it as an answer, so I can mark it as the best answer ) Thanks!
Answer by palash_bhowmick1 · Jul 27, 2014 at 02:09 PM
If it has a Rigidbody attached,go to Rigid body>Constraints. Then check the box of Freeze-Position Z & also Freeze-Rotation Z...That will make its Z-position freeze...Hope this helps you
Your answer
Follow this Question
Related Questions
Lock player position till loading is finished 2 Answers
Camera rotation around player while following. 6 Answers
Lock player position 1 Answer
Locking the mouse cursor without it centering after unlocking it? 0 Answers
Changing player's moving direction 0 Answers