- Home /
2D - locking the z axis using CharacterController.move
Here is my code so far.
Vector3 movement = new Vector3(Input.GetAxis ("Horizontal") *MoveSpeed*Time.deltaTime, Input.GetAxis("Jump")*JumpHeight*Time.deltaTime,0);
cc.Move (movement);
cc.SimpleMove(Physics.gravity);
It works great, other than when I continuously run into a wall, my object starts to move in the z direction and eventually falls off the course. How do I lock him to position.z = 0?
I have tried this, but it doesn't work.
Vector3 pos = transform.position;
pos.z = 0;
transform.position = pos;
The character is still able to move in the z direction, and the gravity stops working correctly.
Thanks for your help.
Edit: I've also tried adding a rigid body, making it kinematic, switching off gravity, and freezing z position, it still slides into the z position while I move it into an angled cube
Answer by asasababoon · Feb 09, 2014 at 05:36 PM
add a rigid body, that is kinemetatic, no gravity, freeze Z position
Still not working. After adding a rigid body, making it kinematic, switching off gravity, and freezing z position, it still slides into the z position while I move it into an angled cube. Thanks for your help though.
Your answer
Follow this Question
Related Questions
Locking the Z-axis based on direction 0 Answers
Lock the screen 1 Answer
Lock cursor everywhere not center,how? 1 Answer
Quaternion LookRotation/Slerp Axis Lock 3 Answers