Giter Club home page Giter Club logo

arcadespaceflightexample's Introduction

Arcade Space Flight Physics Example

Simple example of arcade style space sim flight physics. Built with Unity 5.6.

screenshot

Download

You can either clone the repository, or download either the demo or asset package from the releases page.

Controls

There are two control modes supported. The first is mouse flight and the second is traditional. They can be toggled by checking the "Use Mouse Input" property on the ShipInput component.

Mouse Controls

  • W/S: Increase/Decrease throttle
  • A/D: Strafe Left/Right
  • Mouse scrollwheel: Increase/Decrease throttle
  • Mouse motion: Pitch/Yaw

Traditional Controls

  • W/S: Pitch Down/Up
  • A/D: Yaw Left/Right
  • R/T: Increase/Decrease throttle

Note that with the traditional control setting, a gamepad or joystick's X/Y axes can be used for flight as well.

Component Organization

When possible, I like to break things off into very self-contained components. This isn't always possible, but I feel it's a good practice in general that keeps your source files small and easily understood. However, this does add some complexity in that it requires you to link components together in some way.

Personally, I prefer doing these associations in code, especially when the components are likely to be on the same GameObject. In the case of the ship, it's made of three different components: Ship, Input, and Physics. The way I configured it here, the Ship component is meant to represent the entire ship. All external access to ship properties such as velocity or input are meant to go through the ship. In an effort to keep individual components as dumb as possible, and to minimize cross-component dependency, they communicate (only if necessary) to the ship, rather than other components directly. While there isn't an example of this in the project, each component has a reference to the ship just in case. The ship itself also passes information between components as needed.

There are advantages and disadvantages to this method, but I think it's worth showing as an example of one way to tackle complex component interaction.

Ship

As mentioned above, the ship component represents the ship as a whole and provides a communication mechanism between components.

Ship Input

In keeping with the mentality of separating out responsibilities, this component handles all input. In this example, only player input is considered, but it would be trivial to add a flag here to ignore player input if this isn't the player (by checking ship.isPlayer). A great use case for this would be if you want an AI to instead drive the input. Having an input layer between the player/AI, and the ship itself, allows the ship to only care about ship input and not where it's coming from.

Ship Physics

This component is taken almost verbatim from my UnityCommon repository. It's a generic space physics component that can apply forces and torques to a rigidbody using inputs that a ship's input would give. You give it the forces that it can apply in each axis, and then how much of those forces to apply.

Changelog

1.0 08/24/2017

  • Initial commit

arcadespaceflightexample's People

Contributors

brihernandez avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.