Hi All,
I’m trying to have my space plane rotate on the X and Y Axis, I’ve got it turning but it stops when the mouse stops moving. The behaviour I’m looking for is for the space plane to continue to rotate till the mouse is back in the centre of the screen. This is what I have so far :-
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShipControler : MonoBehaviour
{
private Rigidbody rb;
public float RotationSpeed = 100;
public float Thrust = 5;
// Start is called before the first frame update
private void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
float xAxisRotation = Input.GetAxis("Mouse Y"); // up/down rotates the x axis (pitch)
float yAxisRotation = Input.GetAxis("Mouse X"); // left/right rotates the y axis (Yaw)
float tAxisThrust = Input.GetAxis("Thrust"); // Space to thrust
float xRotation = (xAxisRotation * RotationSpeed);
float yRotation = (yAxisRotation * RotationSpeed);
float tThrust = (tAxisThrust * Thrust);
xRotation *= Time.deltaTime;
yRotation *= Time.deltaTime;
tThrust *= Time.deltaTime;
rb.AddForce(transform.forward * tThrust, ForceMode.Impulse);
transform.Rotate(xRotation, yRotation,0);
}
}
Any and all help greatly appreciated!