Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerControl : MonoBehaviour
- {
- // All movement will be based aroud these speeds, this will help us speed up and down the ship as needed
- public float Base_Speed;
- public float Turn_Speed;
- //Using public floats allows us to edit the values without going into the script
- private Rigidbody rb;
- // Use this for initialization
- void Start()
- {
- //At the beginning of the scene create a shortcut "rb" to mean gather the data in the rigidbody component.
- rb = GetComponent<Rigidbody>();
- }
- void Update()
- {
- //This will only be used while the camera is a child of the plane, later on we will make this code obsolette
- //Turns the Ship towards the mouse, by defult is inverted.
- float h = Turn_Speed * Input.GetAxis("Mouse X");
- float v = Turn_Speed * -Input.GetAxis("Mouse Y");
- transform.Rotate(v, h, 0);
- }
- // Update is called once per frame before any and all physics calulations are made
- void FixedUpdate()
- {
- //Imput.GetAxis is a way for Unity to calulate directions
- float moveHorizontal = Input.GetAxis("Horizontal");
- float moveVertical = Input.GetAxis("Vertical");
- //Using a reletive force gives us more natural movement but can cause some confusion when using world Axes, in some cases the MoveVertical must be inversed to move the ship in the correct direction.
- Vector3 movement = new Vector3(moveHorizontal, 0, moveVertical);
- //Relative Forces allow us to move the ship in the way we see it instead of a third party perspective
- rb.AddRelativeForce(movement * Base_Speed);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment