Advertisement
Guest User

Movimento FPS

a guest
Oct 23rd, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class FPS : MonoBehaviour {
  5.  
  6.     public float speedH = 2.0f;
  7.     public float speedV = 2.0f;
  8.     public Rigidbody m_Rigidbody;
  9.  
  10.     private float yaw = 0.0f;
  11.     private float pitch = 0.0f;
  12.  
  13.     public float m_Speed = 5f;
  14.  
  15.     public void Start(){
  16.  
  17.         m_Rigidbody = this.GetComponent<Rigidbody>();
  18.     }
  19.  
  20.     void Update () {
  21.         yaw += speedH * Input.GetAxis("Mouse X");
  22.         pitch -= speedV * Input.GetAxis("Mouse Y");
  23.  
  24.         transform.eulerAngles = new Vector3(pitch, yaw, 0.0f);
  25.  
  26.  
  27.         if (Input.GetAxis("Vertical") != 0){
  28.             m_Rigidbody.velocity = transform.forward * m_Speed * Input.GetAxis("Vertical");
  29.         }
  30.  
  31.         if (Input.GetAxis("Horizontal") != 0){
  32.             m_Rigidbody.velocity = transform.right * m_Speed * Input.GetAxis("Horizontal");
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement