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,
Answer by Loius
Nov 26, 2010 at 05:34 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.
Ok, Ill try that now...
Just to add here, is this intentional, not to use the actual Move or SimpleMove funcions of Character Controller?
Ok, still needs some adjustments, still very jerky movement but, lets see how it goes under testing with other movements like jumping etc... Thank you Vicenti for your help. :D
You could use .Move; that would let you check to make sure the character actually can un-crouch (if they're in a narrow pass, you could undo the uncrouch). Getting the animation to sync with the sudden movement is the tricky part; I haven't gotten around to implementing this yet in my game, unfortunately, so I don't have any concrete examples.
Yes, the .Move, because this is whats recommended for moving the character collider (at least from what Ive read so far), thats why I asked about it... Now, the thing that I think worked is because there is no interference with gravity, because gravity is being applied as a Move function... So by using translate, maybe this gave an extra moving possibility without altering gravity.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a user guide.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
Answers and Comments
1 Person is following this question.
Collision normal angles.
character bounces on a box
Can a character collider be affected by a rigidbody collider?
add camera collision without CharacterController
Looks like I having new problems with unity collider...