• Stars
    star
    270
  • Rank 151,441 (Top 3 %)
  • Language
    C#
  • License
    Other
  • Created over 5 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Spaceship flight in a similar style to Freelancer

FreelancerFlightExample

This project is an example of Freelancer style mouse controls. One of the most notable things about the game was that it practically "solved" the problem of playing space games with a mouse and keyboard. While setting up a virtual joystick as seen in my other space flight example, isn't too difficult, Freelancer used a fundamentally different solution. Its end results are mostly the same, but there are a lot of subtle nuances (arguably good and bad) to the way Freelancer controlled.

screenshot

This project was built in Unity 2017.3.1f1.

Download

You can either clone the repository or download the asset package located in the root.

Demo Controls

Demo plane

Use the mouse to fly the ship around. Use the keyboard to control the throttle and strafe.

  • Mouse wheel: Speed up/down
  • W/S: Speed up/down
  • A/D: Strafe left/right

How to Use

As this is more of a demo/example than an asset, I won't be describing how to apply this to standalone projects. However, as this is built off of the ArcadeSpaceFlightExample project, it's still a fairly straightforward architecture and set of prefabs.

  1. Load the Flight scene. You will see the ship and two camera rigs.
  2. By default the ComplexCameraRig prefab is enabled. This is the prefab with the juicy camera motions.
  3. If you wish to mess around with the simple rig, disable the ComplexCameraRig and enable the SimpleCameraRig in the scene.
  4. Fly the ship using the controls described above!

Camera Rigs

There are two camera rigs included. The SimpleCameraRig contains the camera code necessary to make this whole system work. As described below, the camera must follow the ship in a specific way in order for the banking to work correctly.

Simple Camera

The ComplexCameraRig includes extra code to mimic the camera motion of Freelancer. The code in this rig is based off of the camera code I wrote for the Freelancer Flight Simulator project. This is not necessary for the demo, but it's a fun camera that I think is worth including.

Complex Camera

Mechanics

While on the surface this appears to be a virtual joystick type control scheme, it's actually more akin to an autopilot. Similar to the Mouse Flight project the player does not directly control the ship. Instead, the player tells the ship where to go, and the ship then flies towards that point.

Virtual Joystick

This is not how this example works, but it's a useful to contrast the difference.

Virtual joystick

The typical approach for this method is to take the mouse position on the screen, then translate it into normalized values meant to emulate a joystick. In the above example, the mouse cursor is up and to the right, which translates to joystick input of 0.8 yaw right, and 0.6 pitch up. Many games use this method as it is simple, consistent, and reliable. This is the method used in the ArcadeSpaceFlightExample project.

The "Turn Towards" Autopilot

Disclaimer: I do not have access to the Freelancer source code, so the following is speculation based on my experience.

FL Banking

Freelancer does something quite different. While on the surface it appears to use a virtual joystick (and for years I believed this was the case) it is instead a fly by wire "turn towards" system very similar to the Mouse Flight project project.

Instead of using the mouse as direct joystick-like input, the mouse cursor is used to project a point somewhere off in the distance, and the ship then automatically turns toward that point. The camera being stuck behind the ship is why it appears to work like a virtual joystick. As long as you hold the mouse to the left of the screen, the ship will continually turn left because the "go to point" is perpetually to the ship's left.

This two channel autopilot takes care of the pitch and yaw. The roll channel is taken care of by the banking.

Banking

FL Banking

The banking is a specific behavior worth talking about separately. When the ship is turning, it will bank (i.e. roll) in that direction by some pre-determined amount. What the banking really is though, is the roll component of the autopilot.

To achieve that cinematic banking, the ship is always rolling to match the camera's own up. This is why it's critical that the camera operates a certain way. The camera must inherit the pitch and yaw movements of the ship, but not the roll, as the ship must be able to roll independently of the camera. See the camera code in the SimpleCameraRig class for more information.

To figure out how much to roll, the mouse on the screen is used. When the mouse is on the rightmost edge of the screen, the ship will try to roll bankLimit degrees to the right, relative to the camera's up. See the BankShipRelativeToUpVector function in the ShipInput class for more details.

Changelog

1.0 (Feb 9 2019)

  • Released

More Repositories

1

MouseFlight

War Thunder style mouse flight controls for aircraft
C#
625
star
2

SimpleWings

A simple, configurable aerodynamic wing that applies lift at its location. Includes flyable example plane.
C#
215
star
3

AceArcadeMissiles

Arcade style missile code, effect, and sound pack.
C#
112
star
4

GunTurrets2

Starting point for turrets that can be mounted on arbitrarily rotating things. More robust version of GunTurrets.
C#
99
star
5

ArcadeSpaceFlightExample

Simple example of arcade style space sim flight physics.
C#
93
star
6

TinyXWingClean

Tech demo for testing JSON-loaded game data
C#
71
star
7

GunTurrets

Starting point for turrets that can be mounted on arbitrarily rotating things.
C#
71
star
8

Ergo

Fly a little ship around with raylib.
C++
62
star
9

GunsAndBullets2

Guns and bullets template designed with simulation games in mind.
C#
56
star
10

ArcadeJetFlightExample

Example project featuring simple arcade flight.
C#
54
star
11

GunsAndBullets

Generic gun and bullets
C#
54
star
12

PhysicsTankExample

Physics based tank
C#
52
star
13

BillboardNebula

Billboard driven space nebula that you can fly in and around
C#
32
star
14

Warthog

WheelCollider driven fun little vehicle like Halo's Warthog.
C#
32
star
15

SundayChallenges

Collection of small prototype/code exploration projects
ShaderLab
32
star
16

MessageTickerUI

Very simple UI element for displaying messages on screen.
C#
31
star
17

UnityCommon

Assortment of commonly re-used tools and code for my Unity projects
C#
30
star
18

FloatingCockpit

Oddball workaround for floating point errors using a disconnected cockpit
C#
28
star
19

TinyCombatTools

Official tools to help add new assets to the game Tiny Combat Arena.
C#
16
star
20

CubeWars

Space shooter
C#
10
star
21

BeamCannon

Freespace 2 style charging beam cannons.
9
star
22

DCSBuildableFARPs

Proof of Concept DCS mission for dynamically "buildable" FARPs from which players can then spawn from.
Lua
4
star
23

FLTextureExporter

Tool for batch exporting all the textures from Freelancer
C#
4
star
24

brihernandez.github.io

Pages
2
star
25

DigitalAirCombat

Server side scripts to turn DCS into a more fast paced, forgiving, and approachable game.
Lua
2
star
26

MacroquadThrusters

Rust
1
star