Created
February 2, 2018 01:07
-
-
Save unity3dcollege/eba946b6fd75bbcbe81d05b04da778c1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class PlayerMovement : MonoBehaviour | |
{ | |
private CharacterController characterController; | |
private Animator animator; | |
[SerializeField] | |
private float moveSpeed = 100; | |
[SerializeField] | |
private float turnSpeed = 5f; | |
private void Awake() | |
{ | |
characterController = GetComponent<CharacterController>(); | |
animator = GetComponentInChildren<Animator>(); | |
} | |
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); | |
animator.SetFloat("Speed", movement.magnitude); | |
if (movement.magnitude > 0) | |
{ | |
Quaternion newDirection = Quaternion.LookRotation(movement); | |
transform.rotation = Quaternion.Slerp(transform.rotation, newDirection, Time.deltaTime * turnSpeed); | |
} | |
} | |
} |
Nice
very instructive script but if anyone doesn't know C# hewon't understand anything and can't adapt the script to his game or whatever he's doing.
no they will, just use bolt or visual scripting
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
very instructive script but if anyone doesn't know C# hewon't understand anything and can't adapt the script to his game or whatever he's doing.