Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerController : MonoBehaviour
  6. {
  7.     private PlayerController characterController;
  8.  
  9.     [SerializeField]
  10.     private float moveSpeed = 100f;
  11.     [SerializeField]
  12.     private float turnSpeed = 5f;
  13.  
  14.     private void Awake()
  15.     {
  16.         characterController = GetComponent<CharacterController>();
  17.     }
  18.  
  19.     private void Update()
  20.     {
  21.         var horizontal = Input.GetAxis("Horizontal");
  22.         var vertical = Input.GetAxis("Vertical");
  23.  
  24.         var movement = new Vector3(horizontal, 0, vertical);
  25.  
  26.         characterController.SimpleMove(movement * Time.deltaTime * moveSpeed);
  27.  
  28.         if (movement.magnitude > 0)
  29.         {
  30.         Quaternion newDirection = Quaternion.LookRotation(movement);
  31.             transform.rotation = Quaternion.Slerp(transform.rotation, newDirection, Time.deltaTime * turnSpeed);
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement