I’ve managed to get it so my character controller is able to accelerate when starting to move but it doesn’t deccelerate at all when I let go of my xbox joystick. I thought it would work based off of what i’ve coded but it seems to be dependant on the input. If anybody can give me some advice as to how to get it to deccelerate I would be grateful. Thanks in advance ![]()
/////// Move
if (Player.isGrounded)
{
Vector3 Movement = new Vector3(HorizontalSpeed, 0, VerticalSpeed);
Movement = transform.rotation * Movement;
Player.Move(Movement * Time.deltaTime);
// Horizontal
// Right
if (Input.GetAxis("Left Joystick Horizontal") >= 1)
{
HorizontalSpeed += Time.deltaTime * Acceleration;
}
else
{
while (HorizontalSpeed > 0)
{
HorizontalSpeed -= Time.deltaTime * Acceleration;
}
}
// Left
if (Input.GetAxis("Left Joystick Horizontal") <= -1)
{
HorizontalSpeed -= Time.deltaTime * Acceleration;
}
else
{
while (HorizontalSpeed < 0)
{
HorizontalSpeed += Time.deltaTime * Acceleration;
}
}
HorizontalSpeed = Mathf.Clamp(HorizontalSpeed, -10, 10);
if (HorizontalSpeed > -0.4 && HorizontalSpeed < 0.4)
{
HorizontalSpeed = 0;
}
// Vertical
// Forward
if (Input.GetAxis("Left Joystick Vertical") >= 1)
{
VerticalSpeed += Time.deltaTime * Acceleration;
}
else
{
while (VerticalSpeed > 0)
{
VerticalSpeed -= Time.deltaTime * Acceleration;
}
}
// Back
if (Input.GetAxis("Left Joystick Vertical") <= -1)
{
VerticalSpeed -= Time.deltaTime * Acceleration;
}
else
{
while (VerticalSpeed < 0)
{
VerticalSpeed += Time.deltaTime * Acceleration;
}
}
if (VerticalSpeed > -0.4 && VerticalSpeed < 0.4)
{
VerticalSpeed = 0;
}
}
You might be confused about the behavior you'll get from this: while (HorizontalSpeed > 0)
– TreyH@sajjad2016 I changed it. You just need to write a function yourself that gets the current scale value
– Cornelis-de-Jager