- Home /
Unslide does not revert back to normal
I know that a lot of questions alike to this have already been asked, but my problem is that when the player stops sliding, the character controller either (A) grows to a size less than the original, or (B) falls through the floor (because the bounds of the controller's collision pass through the ground). Here is my code:
if (isSliding)
{
tempCenter.y = controller.height/4;
controller.center.y = tempCenter.y;
//controller.center.y = 0.25;
controller.height = 0.5; // height is slide height
moveDirection.z = 2.0; // speed is slide speed
controller.Move(moveDirection * Time.deltaTime);
slideTimer += Time.deltaTime;
if (slideTimer > slideTimerMax) //stop sliding (part I need help with)
{
isSliding = false;
moveDirection.z = 3.0; //speed is normal
transform.position.y += 10;
controller.center = Vector3(transform.position.x,0.5,transform.position.z);
//tempCenter.y = controller.height/4;
//controller.center.y += 5.0;
//controller.center.y = tempCenter.y;
controller.height = 1.0;
}
}
if (!isSliding)
{
speed = 3.0;
controller.Move(moveDirection * Time.deltaTime);
}
All of the lines of code that were commented out are different approaches I have tried to use. No matter what value I set (high/low, pos/neg, mult/div) I always end up with a smaller position on the y axis than what I started with. Help would be greatly appreciated as I cannot figure out how to solve the problem.
Answer by Ostinyo · Jul 18, 2013 at 08:40 PM
I seem to have fixed the problem. The main thing was that the force of gravity on my character controller was too great. I ended up not changing the center of the character controller at all, but instead using transform.position.y += 1.
Your answer
![](https://koobas.hobune.stream/wayback/20220613110410im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Struggling with jumping! 3 Answers
Collision Detection 0 Answers
Increasing Camera "Bobbing" speed when character is sprinting 1 Answer