Advertisement
Guest User

TP_Motor.cs

a guest
Mar 18th, 2014
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class TP_Motor : MonoBehaviour {
  5.  
  6.     public static TP_Motor Instance;
  7.  
  8.     public float MoveSpeed = 10f;
  9.  
  10.     public Vector3 MoveVector { get; set; }
  11.  
  12.  
  13.  
  14.     // Use this for initialization
  15.     void Awake ()
  16.     {
  17.         Instance = this;
  18.     }
  19.    
  20.     // Update is called once per frame
  21.     public void UpdateMotor()
  22.     {
  23.         SnapAlignCharacterWithCamera ();
  24.         ProcessMotion ();
  25.     }
  26.  
  27.     void ProcessMotion()
  28.     {
  29.         // Transform MoveVector to World Space
  30.         MoveVector = transform.TransformDirection (MoveVector);
  31.  
  32.         // Normalize MoveVector if Magnitude > 1
  33.         if (MoveVector.magnitude > 1)
  34.             MoveVector = Vector3.Normalize (MoveVector);
  35.  
  36.         // Multiply MoveVector by MoveSpeed
  37.         MoveVector *= MoveSpeed;
  38.  
  39.         // Multiply MoveVector by DeltaTime
  40.         MoveVector *= Time.deltaTime;
  41.  
  42.         // Move the Character in World Space
  43.         TP_Controller.CharacterController.Move (MoveVector);
  44.     }
  45.  
  46.     void SnapAlignCharacterWithCamera()
  47.     {
  48.         if (MoveVector.x != 0 || MoveVector.z != 0)
  49.         {
  50.             transform.rotation = Quaternion.Euler(transform.eulerAngles.x,Camera.mainCamera.transform.eulerAngles.y,transform.eulerAngles.z);
  51.         }
  52.     }
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement