Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerController : MonoBehaviour
- {
- private PlayerController characterController;
- [SerializeField]
- private float moveSpeed = 100f;
- [SerializeField]
- private float turnSpeed = 5f;
- private void Awake()
- {
- characterController = GetComponent<CharacterController>();
- }
- private void Update()
- {
- var horizontal = Input.GetAxis("Horizontal");
- var vertical = Input.GetAxis("Vertical");
- var movement = new Vector3(horizontal, 0, vertical);
- characterController.SimpleMove(movement * Time.deltaTime * moveSpeed);
- if (movement.magnitude > 0)
- {
- Quaternion newDirection = Quaternion.LookRotation(movement);
- transform.rotation = Quaternion.Slerp(transform.rotation, newDirection, Time.deltaTime * turnSpeed);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement