Advertisement
brainode

Untitled

Jul 27th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.93 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5.  
  6. public class PlayerController : MonoBehaviour
  7. {
  8.  
  9.     [SerializeField]
  10.     private float fPlayerSpeed = 20F;
  11.     [SerializeField]
  12.     private float fPlayerJumpVelocity = 150;
  13.  
  14.     private Vector3 v3Move;
  15.     private Rigidbody rbPlayer;
  16.  
  17.     #region Animation
  18.     private Animator anrPlayer;
  19.    
  20.     private int iJumpHash = Animator.StringToHash("Jump");
  21.     private int iAttackHash = Animator.StringToHash("Attack");
  22.     private int iForwardHash = Animator.StringToHash("Forward");
  23.  
  24.     private int iMovementButtons = 0;
  25.     #endregion
  26.  
  27.     void Start () {
  28.         rbPlayer = GetComponent<Rigidbody>();
  29.         anrPlayer = GetComponentInChildren<Animator>();
  30.     }
  31.    
  32.     void FixedUpdate () {
  33.         v3Move.x = Input.GetAxisRaw("Horizontal") * fPlayerSpeed;
  34.         v3Move.y = Physics.gravity.y;
  35.         //v3Move.y = 0;
  36.         v3Move.z = Input.GetAxisRaw("Vertical") * fPlayerSpeed;
  37.         v3Move = transform.TransformDirection(v3Move);        
  38.         v3Move.Normalize();
  39.  
  40.         rbPlayer.velocity =  v3Move*fPlayerSpeed;
  41.         if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.S))
  42.         {
  43.             Debug.Log("FixedUpdate magnitude"+rbPlayer.velocity.magnitude);
  44.         }
  45.  
  46.     }
  47.  
  48.     void Update()
  49.     {
  50.         if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.S))
  51.         {
  52.             Debug.Log("Update magnitude" + rbPlayer.velocity.magnitude);
  53.         }
  54.         Debug.DrawLine(rbPlayer.position, v3Move);
  55.     }
  56.  
  57.     void LateUpdate()
  58.     {
  59.         if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.S))
  60.         {
  61.             Debug.Log("Late magnitude" + rbPlayer.velocity.magnitude);
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement