Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class KnightController : MonoBehaviour
  6. {
  7.  
  8.     float speed = 4;
  9.     float rotSpeed = 80;
  10.     float gravity = 8;
  11.  
  12.     Vector3 moveDir = Vector3.zero;
  13.  
  14.     CharacterController controller;
  15.     Animator anim;
  16.  
  17.  
  18.  
  19.    
  20.     void Start()
  21.     {
  22.         controller = GetComponent<CharacterController>();
  23.         anim = GetComponent<Animator>();
  24.        
  25.     }
  26.  
  27.  
  28.     void Update()
  29.     {
  30.         if (controller.isGrounded)
  31.         {
  32.  
  33.             if (Input.GetKey(KeyCode.W))
  34.             {
  35.                 moveDir = new Vector3(0, 0, 1);
  36.                 moveDir *= speed;
  37.  
  38.             }
  39.         }
  40.         moveDir.y -= gravity * Time.deltaTime);
  41.         controller.Move(moveDir * Time.deltaTime);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement