Hello, I’m using the character controller component for a 2D platformer. When I Jump and when my player hits the ceiling while moving it kind of sticks to the ceiling.
this is my move function:
void Move()
{
if(controller.collisionFlags == CollisionFlags.Above)
{
jumpCount = maxJumpCount;
verticalVelocity = moveDirection.y;
}
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= moveSpeed;
moveDirection = new Vector3(moveDirection.x, verticalVelocity, moveDirection.z);
moveDirection = new Vector3(moveDirection.x, (moveDirection.y - gravity * Time.deltaTime), moveDirection.z);
if(controller.isGrounded && moveDirection.y < -1)
moveDirection = new Vector3(moveDirection.x, (-1), moveDirection.z);
controller.Move(moveDirection * Time.deltaTime);
}
verticalVelocity is set upon pressing the jump button.
When the player jumps and hits its head it comes down immediately, it only happens while moving.
EDIT: The moveDirection is set to Vector3.zero at the start of the update.
When I print the vector before setting the verticalVelocity, the y-value is always 0, even when I move while hitting the ceiling. The character is just not coming down.