Advertisement
marcelpace

First Person Camera Script - Unity

Feb 1st, 2019
2,832
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. //Eu to colocando esse script numa esfera, e dentro dessa esfera a câmera.
  2. //Eu só não to conseguindo fazer o personagem se mover em direção a câmera.
  3. //Eu acho que a solução tem a ver com isso aqui:
  4. //https://docs.unity3d.com/ScriptReference/Space.html
  5.  
  6.  
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. using UnityEngine;
  10.  
  11. public class Controller : MonoBehaviour {
  12.  
  13. public float speed;
  14.  
  15. public float speedNormal = 10.0f;
  16. public float speedFast = 50.0f;
  17.  
  18. public float mouseSensitivityX = 5.0f;
  19. public float mouseSensitivityY = 5.0f;
  20.  
  21. float rotY = 0.0f;
  22.  
  23. private Rigidbody rb;
  24.  
  25. void Start () {
  26. rb = GetComponent<Rigidbody>();
  27. }
  28.  
  29. void FixedUpdate () {
  30. float moveHorizontal = Input.GetAxis ("Horizontal");
  31. float moveVertical = Input.GetAxis ("Vertical");
  32.  
  33. Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
  34.  
  35. rb.AddForce (movement * speed);
  36. }
  37.  
  38. void Update() {
  39. float rotX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * mouseSensitivityX;
  40. rotY -= Input.GetAxis("Mouse Y") * mouseSensitivityY;
  41. rotY = Mathf.Clamp(rotY, -89.5f, 89.5f);
  42. transform.localEulerAngles = new Vector3(-rotY, rotX, 0.0f);
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement