public class PlayerMovement : MonoBehaviour
public float rotationSpeed;
private CharacterController characterController;
private float originalStepOffset;
characterController = GetComponent<CharacterController>();
originalStepOffset = characterController.stepOffset;
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");
Vector3 movementDirection = new Vector3(horizontalInput, 0, verticalInput);
float magnitude = Mathf.Clamp01(movementDirection.magnitude) * speed;
movementDirection.Normalize();
ySpeed += Physics.gravity.y * Time.deltaTime;
if (characterController.isGrounded)
characterController.stepOffset = originalStepOffset;Share
if (Input.GetButtonDown("Jump"))
characterController.stepOffset = 0;
Vector3 velocity = movementDirection * magnitude;
characterController.Move(velocity * Time.deltaTime);
if (movementDirection != Vector3.zero)
Quaternion toRotation = Quaternion.LookRotation(movementDirection, Vector3.up);
transform.rotation = Quaternion.RotateTowards(transform.rotation, toRotation, rotationSpeed * Time.deltaTime);