- Home /
(Solved) Character Floats After Hitting Head on Object
Basically the character is "hanging" after you jump and he hits his head on a platform only while move left or right. If you are standing still he hits his head and returns normally to the ground (mario style). If you are moving to the left or right he will float for a short while until gravity picks him back up again. If you leave from under the platform you hit he falls normally right away.
It's a problem that I've had since the beginning and I'll spend a few hours trying to fix it, leave defeated only to come back and spend a few more hours on it another day. The cycle repeats. Any help would be immensely appreciated! :)
Cheers
// Move the controller, and set collidedDown true or false depending on whether we're standing on something
flags=controller.Move(moveDirection*Time.deltaTime);
//Detect character controller collision
collidedDown=(flags & CollisionFlags.CollidedBelow)!=0;
collidedUp=(flags & CollisionFlags.CollidedAbove)!=0;
collidedSides=(flags & CollisionFlags.CollidedSides)!=0;
if(collidedUp){
moveDirection.y=0;
}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
so I made my comment an answer and put the corrected code in there :) would you please click on the tick button under the dislike to accept it :)
@ddmx do not edit the title as solved. How to accept an answer :
On the left-hand-side of the Answer box , there are the following icons :
Thumb Up
Number (of votes)
Thumb Down
A Tick/Check $$anonymous$$ark
If an answer worked for you , click on the 'Tick' , the answer should now be highlighted in green. If you like an answer on Any question , you can click on the Thumb UP , the thumb should now be highlighted in green , and the number of votes should rise by 1.
When your karma rises above 15, you can upvote any answer (on any question) you like or think is correct, this gives the person karma for their time and effort.
Watch : http://video.unity3d.com/video/7720450/tutorials-using-unity-answers
Thanks for pointing that out. I checked it and now everyone should get the credit they deserve. :)
Cheers
Answer by Benproductions1 · Feb 23, 2013 at 04:14 AM
Your problem is, that your setting move direction to 0. When your character hit's something, it goes "into" it, so for a short amount of time his velocity will always be 0 how about setting it to 0 only if it's above 0?
if (collidedup && moveDirection > 0) {
moveDirection = 0;
}
Your answer
Follow this Question
Related Questions
controller.Move not working correctly 0 Answers
How to make the CC(character controller) jump and push 1 Answer
Character Jumping Not Working Sometimes 1 Answer
can anyone help me to smooth the jump? 0 Answers
tring to make a jump pad in fps 1 Answer