when crouch, falling through floors

Hey guys,

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,

more ▼

asked Nov 26, 2010 at 05:23 PM

Caps gravatar image

123 25 23 29

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Nov 26, 2010 at 05:34 PM

Loius gravatar image

15k 36 49 95

Ok, Ill try that now...

Nov 26, 2010 at 06:05 PM Caps

Just to add here, is this intentional, not to use the actual Move or SimpleMove funcions of Character Controller?

Nov 26, 2010 at 06:09 PM Caps

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

Nov 26, 2010 at 07:19 PM Caps

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.

Nov 27, 2010 at 07:41 AM Loius

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.

Nov 28, 2010 at 04:35 AM Caps
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Nov 26, 2010 at 05:23 PM

Seen: 2762 times

Last Updated: Sep 03, 2012 at 02:34 AM