I am working on a 2d scroll type game. The problem I am currently having is that when the character controller hits a slopped surface ( in this case in the z direction) it slides in that direction. Is there a way i can freeze z translation? I could simple add a method to update to continuously ensure that players.transform.x stays the same but this seams to be a bit expensive to fix a simple issue.
Your comments would be greatly appreciated.
Thank You
TWest
Try this
function Update(){
transform.position.z = 0; // it put the player on z= 0, change it if you want other z position
}
I was hoping for something a bit more elegant but I think this should work.
Thank You
If your character has a rigidbody component you can restrict movement and rotation for each axis individually. in your case locking movement along the Z-Axis should get the job done.
Either do it in the inspector, or you can set the constraints through script:
Hi
I have a similar issue I guess. My character moves in a circumference around the center of the scene. That works fine, except when I run into an obstacle, lets say a wall, it stops running as expected but starts sliding sideways through the wall until it ends up falling off the platform.
I’m using a Character Controller and basically what I do is move my character forward on update and correct the facing angle so next time the forward direction would be different.
Any ideas?
Thanks
Joe