- Home /
Player Diagonal Velocity
I am having this issue.. That happens to many people, and usually using normalize... would solve this. I guess it does but my players speed decreases immensely. Is there any way I can fix my diagonal speed so it isn't faster than Horizontal and Vertical separately, that would not change my players movement speed after normalizing?
void MovePlayer()
{
float moveFB = Input.GetAxis("Horizontal") * walkSpeed;
float moveLR = Input.GetAxis("Vertical") * walkSpeed;
Vector3 movement = new Vector3(moveFB, verticalVelocity, moveLR);
movement = transform.TransformDirection(movement);
charController.Move(movement * Time.deltaTime);
}
I would like to add to it... When I Normalize... It bugs my Player Jumping and also the player doesn't stop moving for some bit after lettings go of the Move Button.
Answer by tormentoarmagedoom · May 30, 2018 at 08:41 AM
Good day.
You need to divide it by
If (moveFB != 0 && moveLR != 0) // This means is moving diagonally
{
....
charController.Move ((movement / 1.414f) * Time.deltaTime);
}
Bye!! :D (Accept the answer so other people can easy find the solution) :D
As an alternative way of looking at this, I like to keep in $$anonymous$$d the idea that the player could be using a gamepad with analog control.
Implementing that essentially means only worrying about adjusting the input vector if it exceeds a magnitude of 1, but still considering the possibility of inputs which aren't exclusively 0 or 1.
Vector2 controlInput = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
if(controlInput.sqr$$anonymous$$agnitude > 1.0f)
{
controlInput.Normalize();
}
Vector2 scaledInput = controlInput * walkSpeed;
// ...
Thank you very much! Seems to be working fine.. (I thought of doing something similar but I couldn't find the correct number to do so ^^)
Your answer
Follow this Question
Related Questions
question with character controller to move with hitting mousebuttton down 1 Answer
Roll/Dodge/Evade System 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers