Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Movement_1 : MonoBehaviour
- {
- public Transform player_camera, center_point;
- KeyCode moveF;
- KeyCode moveB;
- KeyCode moveR;
- KeyCode moveL;
- float zoom;
- float mouseX;
- float mouseY;
- Vector3 moveFB;
- Vector3 moveRL;
- public float acc, speed, max_speed;
- Rigidbody rb;
- private void Start()
- {
- moveF = KeyCode.W;
- moveB = KeyCode.S;
- moveR = KeyCode.D;
- moveL = KeyCode.A;
- zoom = -5f;
- player_camera.transform.position = new Vector3(0, 2, zoom);
- mouseX = 0;
- mouseY = 0;
- moveFB = new Vector3(0, 0, acc);
- moveRL = new Vector3(acc, 0, 0);
- rb = GetComponent<Rigidbody>();
- }
- void FixedUpdate()
- {
- mouseX += Input.GetAxis("Mouse X");
- mouseY -= Input.GetAxis("Mouse Y");
- mouseY = Mathf.Clamp(mouseY, 0f, 50f);
- center_point.localRotation = Quaternion.Euler(mouseY, 0, 0);
- if (Input.GetKey(moveF))
- {
- if (rb.velocity.magnitude < speed)
- {
- rb.AddRelativeForce(Vector3.forward + moveFB);
- }
- }
- else if (Input.GetKey(moveB))
- {
- if (rb.velocity.magnitude < speed)
- {
- rb.AddRelativeForce(Vector3.forward - moveFB);
- }
- }
- if (Input.GetKey(moveR))
- {
- if (rb.velocity.magnitude < speed)
- {
- rb.AddRelativeForce(Vector3.forward + moveRL);
- }
- }
- else if (Input.GetKey(moveL))
- {
- if (rb.velocity.magnitude < speed)
- {
- rb.AddRelativeForce(Vector3.forward - moveRL);
- }
- }
- transform.localRotation = Quaternion.Euler(0, mouseX, 0);
- Debug.Log($"velocita' {rb.velocity.magnitude}");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement