Hi there, so I’m attempting to correct the issue with the provided CharacterController.Move script in the API that causes the controller to move at twice the rate of speed when moving diagonally. I’ve been cracking at it with my Google-Fu for hours to no avail. It seems the solutions that are working for others work for me as well but come with the added pain of being unable to move faster than a crawl. Here’s the current code I’m working with.
CharacterController controller = GetComponent<CharacterController>();
if (!controller.isGrounded)
{
moveDirection.x = Input.GetAxis("Horizontal") * airSpeed;
moveDirection.z = Input.GetAxis("Vertical") * airSpeed;
}
// If grounded, zero out y component and allow jumping
else
{
moveDirection.x = Input.GetAxis("Horizontal");
moveDirection.z = Input.GetAxis("Vertical");
Vector3 newMoveDirection = new Vector3(moveDirection.x, 0, moveDirection.z);
newMoveDirection *= groundSpeed;
if (newMoveDirection.magnitude > 1.0f)
{
newMoveDirection = newMoveDirection.normalized;
}
if (Input.GetButton("Jump"))
{
moveDirection.y = jumpSpeed;
}
}
moveDirection = transform.TransformDirection(moveDirection);
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
It may be a bit of a mess due to my persistent fiddling trying to find a solution. At this stage the movement is normalized and you move at the same speed in every direction. It however is extremely slow and adjusting my groundSpeed variable does absolutely nothing. I feel I need an alternative solution to this issue as for whatever reason this hasn’t been working. Any ideas?