Ive been creating a character using the character controller. So I have written my own script to make it move, run, jump and crouch.
Now, everything seems to be working properly, except when the character uncrouches, that means, whe it stands up, it falls through the floor.
The issue is that, when using crouch, the controller.height is being altered from 2 to 1. So, when standing up, its 1 to 2. Thats exaclty the problem, when going back to the height of 2, that height goes through the floor so the character is now insered in the floor, thus falls.
I have already seen a solution where the gravity is "zeroed" or "stopped" for standing/uncrouching, but that really is not a solution for me because the player should be able to jump and crouch and also stand while in a jump.
Also I have tried smoothing this transition in controller.height, so it gradualy goes from 1 to 2 and 2 to 1, still not working, player falls through.
I have also tried giving a "little impulse" somewhat similar to stopping gravity, wich in this case it works, but again, not a good solution.
I have also tried setting the controller.center.y, wich would be an alternative way of changing the colliders position while standing so it doesnt go through floor but Ive had no success yet.
Would someone please give me any suggestions? I bet me and a lot of people would appreciate it!
Thanks in advance,
asked Nov 26, 2010 at 05:23 PM
You have to move the character controller (that is, transform.position.z += 1) so it's not clipping the ground. If it clips through something when its size is changed, it'll fall right through.
answered Nov 26, 2010 at 05:34 PM