I currently have basic movement system for my space which is W to go forward and rotates using the mouse but doesn’t feel realistic at all and is too clunky feeling. So does anyone know any good scripts I cam implement or tips that would make a good spaceship/airplane movement mechanic? Preferably third person but first person ship controls are very similar to third person anyway. Really appreciate it. If you want any more specifics then I’ll add them
I was practicing my java with a ship script, feel free to use it. I am more familiar with C# so I wasn’t sure about how to use the Input.mousePosition in javascript, so you’ll get an error saying:
INTERNAL_get_mousePosition is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake or Start instead. Called from MonoBehaviour 'ship_control' on game object 'Player'.
See "Script Serialization" page in the Unity Manual for further details.
But anyways, a basic, uncluttered system, and it works, I made one for C# but can’t find it.
Here’s the javascript (ship_control.js), just add it to your ‘Player’ object and then attach the camera as a child of the ‘Player’. You can also add a 3D model of a spaceship as a child of the ‘Player’ object too.
public var MousePosition = Input.mousePosition;
public var position;
public var curShipSpeed : float = 0.0;
public var step = 2;
public var current_speed = 0;
public var maxSpeed : int = 100;
public var mouse_rotate = 0.5;
public var agility = 30;
public var dist_fr_ship = 2.85;
public var rotate_speed = 2.0;
function Update () {
if (Input.GetKey ("d"))
{
transform.Rotate(0,0,-rotate_speed);
}
if (Input.GetKey ("a"))
{
transform.Rotate(0,0,rotate_speed);
}
if ((Input.GetKey("up") || Input.GetKey("w")) && (current_speed < maxSpeed)) {
current_speed += step;
} else if ((Input.GetKey("down") || Input.GetKey("s")) && (current_speed > 0)) {
current_speed -= step;
}
MousePosition = Input.mousePosition;
MousePosition.x = (Screen.height/2) - Input.mousePosition.y;
MousePosition.y = -(Screen.width/2) + Input.mousePosition.x;
transform.Rotate(MousePosition * Time.deltaTime * mouse_rotate, Space.Self);
curShipSpeed = Mathf.Lerp(curShipSpeed, current_speed, Time.deltaTime * step);
transform.position += transform.TransformDirection(Vector3.forward) * curShipSpeed * Time.deltaTime;
}