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;
- //public float Rotate_Speed;
- //Using public floats allows us to edit the values without going into the script
- private Rigidbody rb;
- // Define the rotational speed
- public float torque;
- public float moveSprint;
- // Use this for initialization
- void Start()
- {
- 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");
- float moveJump = Input.GetAxis("Jump");
- float turn = Input.GetAxis("Turn");
- float moveSprint = Input.GetAxis("Sprint");
- //Using a reletive force gives us more natural movement but can cause some confusion when using world Axes, in the case the MoveVertical must be inversed to move the ship in the correct direction.
- Vector3 movement = new Vector3(moveHorizontal, moveJump, ((3/2) + moveSprint) * 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);
- rb.AddTorque(transform.forward * torque * -turn);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment