Whereas your current setup has non-orthogonal movement being being calculated at >1 magnitude. ![]() The reason being is this will ensure that you always move in any direction with the same magnitude (1) no matter the angle. You will want to use the normalized vector of the two axes when you multiply by your walkSpeed. M圜haracterController.Move(moveDirection * ltaTime) MoveDirection = transform.TransformDirection(moveDirection) MoveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")) Private Vector3 moveDirection = Vector3.zero ĬharacterController m圜haracterController = null You can also simplify and reduce the code in the MovePlayer function by using Vector3 and TransformDirection. Subtract moveDirection.y by the gravity multiplied by ltaTime. Ware the result is not exactly the same, but still is in the same Vector/vector.sqrMagnitude instead of vector.normalized but be To reduce the processing weight you can use Vector.magnitude is obtained from sqrt(vector.sqrMagnitude) which Vector.normalized is obtained from vector/vector.magnitude and Vector3 distance = direction * walkSpeed * ltaTime Vector3 direction = (moveDirectionForward + moveDirectionSide).normalized Vector3 moveDirectionSide = transform.right * horizontalInput ![]() ![]() Vector3 moveDirectionForward = transform.forward * verticalInput Calculate the Direction to Move based on the tranform of the Player Get Horizontal and Vertical Inputįloat horizontalInput = Input.GetAxis ("Horizontal") įloat verticalInput = Input.GetAxis ("Vertical") The solution is to use a normalized vector for the direction of the movement.
0 Comments
Leave a Reply. |