Constant Flight Control On Mose Movement

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!

Probably could get an answer in the Scripting forum.
But I’ll try.

Using Input.— just gets what is happening in the current frame.
If the mouse stops moving rotation goes to zero.

Since you are assuming that screen center should be zero rotation, you can check to see how far the mouse is away from center. Then assume a certain rotation per pixel distance. Also make a box area that is zero rotation since it would be impossible to hit if it was a single pixel for zero.

So the ship rotates faster the further the mouse is from center.