Skip to content

Instantly share code, notes, and snippets.

@unity3dcollege
Created February 2, 2018 01:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save unity3dcollege/eba946b6fd75bbcbe81d05b04da778c1 to your computer and use it in GitHub Desktop.
Save unity3dcollege/eba946b6fd75bbcbe81d05b04da778c1 to your computer and use it in GitHub Desktop.
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);
}
}
}
@Ziedch
Copy link

Ziedch commented Jun 28, 2021

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.

@WilliamLuppi
Copy link

Nice

@OpenEvade
Copy link

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