- Home /
How to slow player on x and z
In my game i have some code to stop the player moving too fast but it also affects how fast it falls. I want to make it so that it is restricted on the x and z axis but leave the y axis so it can fall faster. Thanks
What if you ins$$anonymous$$d detected if you are falling (y velocity is negative), and disable velocity limiting in this case?
I don't think that will work because if i move when falling, the player will go too fast. Thanks for the comment anyway
O$$anonymous$$, I thought your character can't control its movement when falling.
In that case, still separating the case when you are falling and when not, you can try take the horizontal speed, limit it, then add back the vertical speed. Something like this:
private void LimitSpeed (Vector3 velocity) {
if (falling) {
float verticalSpeed = velocity.y;
Vector3 horizontalVelocity = new Vector3(velocity.x, 0, velocity.z);
// limit horitontal velocity
limitedVelocity += verticelSpeed * Vector3.up;
}
else {
...
}
}
Answer by Yuvii · May 04, 2018 at 09:43 AM
Hey,
As Harinezumi commented, your velocity limitations are usefull when the character isn't falling. So try to detect when the character is falling and then turn off the limitation. Maybe try to look if your character is grounded instead of look for his Y velocity (he may be going down a hill)
if(character.isGrounded)
{
LimitateVelocity = true;
}else
{
LimitateVelocity = false;
}
something like that maybe. Cheers!
Your answer
Follow this Question
Related Questions
Player Collide with Fast moving Rigidbody to cause Death? 1 Answer
Getting the player to move with platform: Velocity, DistanceJoint, or...? 2 Answers
Velocity powered rigidbody on a moving platform without parenting. 3 Answers
slow addforce 1 Answer
Rigidbody y velocity is stuck on 0, gravity is not turned off. 2 Answers