Guest User

Untitled

a guest
Feb 15th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.78 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. [System.Serializable]
  6. public class CharacterMotor : MonoBehaviour
  7. {
  8.     CharacterController characterController;
  9.     //Transform transform;
  10.  
  11.     [Header("Movement")]
  12.     [SerializeField]
  13.     private float runSpeed;
  14.     [SerializeField]
  15.     private float jumpSpeed;
  16.  
  17.     [Header("Physics")]
  18.     [SerializeField]
  19.     private float gravity;
  20.  
  21.     public Vector3 movement = Vector3.zero;
  22.  
  23.     /*
  24.     public CharacterMotor(CharacterMotor myMotor, CharacterController myController, Transform myTransform)
  25.     {
  26.         characterController = myController;
  27.         transform = myTransform;
  28.  
  29.         runSpeed = myMotor.runSpeed;
  30.         jumpSpeed = myMotor.jumpSpeed;
  31.         gravity = myMotor.gravity;
  32.     }
  33.     */
  34.  
  35.     private void Start()
  36.     {
  37.         characterController = GetComponent<CharacterController>();
  38.     }
  39.  
  40.     public bool IsGrounded()
  41.     {
  42.         return characterController.isGrounded;
  43.     }
  44.  
  45.     public void Move(float horizontal, float vertical, bool jump)
  46.     {
  47.         if (IsGrounded())
  48.         {
  49.             Vector3 direction = new Vector3(horizontal, 0, vertical);
  50.             if (direction.magnitude > 1)
  51.                 direction = direction.normalized;
  52.             direction *= runSpeed;
  53.             direction = transform.TransformDirection(direction);
  54.             movement = direction;
  55.             if (jump)
  56.             {
  57.                 movement.y = jumpSpeed;
  58.             }
  59.         }
  60.  
  61.         movement.y = movement.y - (gravity * BoltNetwork.FrameDeltaTime);
  62.         characterController.Move(movement * BoltNetwork.FrameDeltaTime);
  63.     }
  64.  
  65.     public void MoveLocal(Vector3 m)
  66.     {
  67.         characterController.Move(m * BoltNetwork.FrameDeltaTime);
  68.     }
  69. }
Add Comment
Please, Sign In to add comment