Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Assets [RELEASED] Sci-Fi Ship Controller - A versatile physics-based controller with playable demos, AI...

Discussion in 'Works In Progress' started by sstrong, Dec 7, 2018.

  1. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    1,454
  2. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    1,454
    We have a pretty strong roadmap for Sci-Fi Ship Controller, but if you have any feature request, drop us a note in the forum or in our Discord channel.
     
  3. Dave_2000

    Dave_2000

    Joined:
    Oct 17, 2015
    Posts:
    51
    Post-Release Updates

    Hi again!

    Now that the first version of Sci-Fi Ship Controller has been officially released on the asset store, we're hard at work at improvements for version 1.1.0. Here's a bit of an overview of what we're doing:

    Ship AI

    The main focus for v1.1.0 is the addition of built-in ship AI. You'll still be able to write your own AI if you want to (as you can now), but you'll now also have the option of using our AI solution.

    Adding AI to a ship will be as simple as everything else in Sci-Fi Ship Controller - you just add the new Ship AI Input Module to that ship. Then, during the game you can use simple API calls (from scripts) to tell the AI what it should do. Our philosophy with the API calls is that everything should be as simple as possible for the user, but should still leave room for customisation.

    So, how does it work?

    AI States

    Our AI works using the concept of states. There are a number of globally-defined states that each AI ship could be in, which define how it makes basic decisions and which direction it tries to move in. Some examples of possible states are:
    - Move To: The ship is simply trying to move to a specific destination, e.g. a ship flying to meet up with a convoy of other ships
    - Stay: The ship has reached a satisfactory position and just wants to stay there, e.g. a ship hovering above a landing pad and waiting for an event to occur
    - Dogfight: The ship is trying to attack one specific other ship without being shot down by that ship, e.g. a ship engaging in space combat with a ship designated as a target by its squadron leader
    - Patrol: The ship is following a specific path while looking out for ships designated as an enemy. If it finds an enemy ship, it will likely activate an event or move into a more suitable state e.g. the dogfight state
    - Follow: The ship is trying to follow a given leader ship, without getting in its way, possibly flying in a specific formation with a group of other ships

    The simplest way to use the ship AI is to use our built-in states. Setting the state with our API is very easy:

    Code (CSharp):
    1. aiShip1.SetState(AIState.dogfightStateID);
    The line of code above sets the current state to the built-in dogfight state. From there, you can pass information to the ship such as targeting information:

    Code (CSharp):
    1. aiShip1.AssignTargetShip(playerShip);
    And that's it! The ship will then execute the specified state behaviour: it will work out all the complicated stuff of what input should be passed to the ship to achieve the goal.

    But that's not all...

    Custom AI States

    As well as the built-in states, you can also add your own custom states. The state is specified by a function that you pass in, which is then called by any ships using that state. In the state function itself you have access to all the built-in behaviours (functions that convert a simple goal, such as going towards a target position, into ship input) that we use in the built-in states. Some examples of built-in behaviours are:
    - Seek: Go straight towards a target
    - Pursuit: Go towards a target, adjusting for its velocity to intercept it
    - Evade: Move away from a moving target, adjusting for its velocity to avoid it
    - Obstacle Avoidance: If there is an obstacle in our path, move around it
    As well as the built-in behaviours, you also have the option to write custom versions of each behaviour if you want to change how the behaviour works (the option for custom behaviours overriding the built-in ones is also available for built-in states). In your state function you can choose how the behaviours are combined together. For instance, the default setting "priority" uses the behaviour in the list that doesn't have an input of zero.

    If all the stuff about custom states seems intimidating, don't worry - you don't have to use them. We're trying as hard as we can to make sure that the built-in states work for the vast majority of use cases. However, the option to write custom states allows developers to extend our built-in AI to fit the very specific needs of their game without having to write their own completely custom AI solution.

    AI Beta

    As a final note, we're considering releasing a beta version of the AI sometime soon with the key features required for release. If you have the full version of Sci-Fi Ship Controller and would like to get your hands on some of the AI stuff early, let us know.

    If you have any feedback about what you'd like to see in AI for Sci-Fi Ship Controller (or any other features, for that matter) let us know as a reply in this forum, or on our discord channel.
     
    eaque, limo, exiguous and 1 other person like this.
  4. TechnicianStudios

    TechnicianStudios

    Joined:
    Aug 6, 2012
    Posts:
    57
    Will this asset support custom controls for Keyboard and Controller using the Unity Input Manager?
     
  5. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    1,454
    We have a dedicated, Player Input Module which supports a wide variety of custom setups. Can you give us a specific scenario so we can give you a more accurate answer? For example, I want to do xyz...
     
    eaque likes this.
  6. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    1,454
    Feature Announcement

    Coming in Sci-Fi Ship Controller v1.1 is support for Unity's new Input System.

    upload_2019-10-5_19-44-3.png

    This will supplement the support we already have for other input systems including:
    • Direct keyboard
    • Legacy Unity input a.k.a. Input Manager
    • Oculus API for VR input
    • Rewired
    • Vive for VR input
    If you own Sci-Fi Ship Controller (v1.0 or newer) and would like access to the beta PM us your name, email address and invoice number. You can also contact us on our Discord channel.
     
    docsavage likes this.
  7. captain_plan_it

    captain_plan_it

    Joined:
    Oct 17, 2019
    Posts:
    2
    I just want to say this asset is quite incredible. I’ve only had unity for a few days and already have something fun to fly around. https://twitter.com/captain_plan_it/status/1184692751629213696?s=21

    I do have one question with the settings. When at a high velocity and turning, like banking 90 degrees left and pulling back on the stick every few degrees the ship tends to sort slow the rotation then speed up. I can figure out what parameter is causing it.
     
  8. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    1,454
    Looks like you're having fun! We'll take a look at high speed banking and see if we can work out what's going on.
     
    captain_plan_it likes this.
  9. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    1,454
    Shortly, Sci-Fi Ship Controller 1.0.2 will be available from the asset store. If using the (new) Unity Input System with SSC, there will be an option to add on-screen controls. This is useful if deploying to mobile or android tablet.

    The on-screen controls are configured to work with the default actions setup by clicking the "Add Events" button. However, you are free to configure them using any actions supported by the Unity Input System. You can also modify the on-screen controls to suit the UI look and feel of your game.

    upload_2019-10-17_13-40-54.png
     
    captain_plan_it likes this.
  10. Dave_2000

    Dave_2000

    Joined:
    Oct 17, 2015
    Posts:
    51
    I assume you're using the arcade physics model?

    What you're describing sounds like drag at high speeds preventing the ship from rotating quickly. If this isn't the behaviour you're looking for, you can disable this by going to the aero tab and ticking "disable drag moments" (a little below the "calculate drag properties" button). Let us know if that fixes your issue.
     
    captain_plan_it likes this.
  11. captain_plan_it

    captain_plan_it

    Joined:
    Oct 17, 2019
    Posts:
    2
    That was the right section, I wound up keeping it on for the feel I was going for, I just needed to increase the flight turn acceleration which overtook the stall in turning at high speed.
     
  12. BlackManatee

    BlackManatee

    Joined:
    Jun 13, 2013
    Posts:
    56
    Hi -- I got SFSC the other day and it's definitely a powerful asset.

    Unfortunately, it's not working very well for my purposes. I'm building a hovercraft-based game that involves both racing and combat (picture a combination of LucasArts' PodRacer, plus Battlezone's classic hovertanks, e.g. https://youtu.be/DqlxEt_N3kk?t=42 ).

    Unlike most hovercraft games, though, I need a very specific behavior in my game: both smooth and rapid changes in hover-height. I've tried (and built) different types of hovercraft assets and scripts, but they've either been cumbersome or too slow.

    The customizable behavior of SFSC seemed ideal, especially because of the arcade feature, which sounded like it would give me more of a Lerp-style customizable altitude-changing curve rather than a strictly physics-based change.

    Unfortunately, all of the "Arcade" SFSC hovercraft I've tried (or customized) have been EXTREMELY "jittery:" they pitch up and down over rough terrain or slopes in a very unnatural (and jarring) way -- more like they're rolling along the terrain on wheeled stilts rather than on a cushion of air. Even when I turn the Responsiveness and Max Acceleration to their lowest values, the jittering persists. And the pitch/roll controls/settings seem to relate only to input responsiveness rather than terrain-following behaviors.

    When I've tried to use the Physics-based hovercraft, they've tended to have less jittery-ness, but they show a different problem: when driving over rough terrain (or "ski-jumping" over bumps or hills), the hovercraft tends to crash nose-down into the ground or -- even worse -- it will go into an endless barrel-roll (even if I've turned on "Limit Pitch/Roll" and "Orient Upwards in Air"). This occurs even when the ship is well within the "Max Check Distance."

    Is there any way to make SFSC usable for my hovercraft game? In all honesty, I'd be happy if I could just get the ground-following behavior to smooth out (like the hovercraft in the Battlezone video I mentioned). I don't need to use ANY of the other flight behaviors, for now; I can use other scripts to control yaw/pitch/roll/steering/etc. -- but I'd like to use SFSC to control the hover-height behavior (smoother ground-following behavior, with variable altitudes I can set via script).

    Any suggestions would be appreciated. For now, I'll have to switch back to my DIY force-based solutions, but I'd love to use SFSC for more sophisticated control over the hovering / terrain-following behavior instead.
     
  13. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    1,454
    Are you using a Unity terrain or another mesh type? Can you also provide us with a screen shot of the kind of rough terrain you are using so that we can replicate something similar in-house?
     
    Last edited: Oct 18, 2019
  14. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    1,454
    New Input System - When this is first installed from Package Manager and setup in Player Input Module, you way need to restart the Unity Editor. We've seen this with Unity 2019.3.0b4 and 2020.1.0a8. It could also apply to earlier versions like 2019.1 and 2019.2.

    Although the exact cause is unknown, it may be the result of Unity changing the "Active Input Handling" value in Player settings which requires a Unity Editor restart to take effect.
     
  15. BlackManatee

    BlackManatee

    Joined:
    Jun 13, 2013
    Posts:
    56
    Thanks for the quick reply. I've captured a quick video showing the terrain-tracking behavior. It's a standard Unity terrain: I simply painted a few hills to test the terrain-tracking. The vehicle is your standard "Classic Hovership (Arcade)" with no changes other than dropping the hover-height responsiveness and acceleration.

    Towards the end of the clip, I've included shots of the hovership's Inspector tab for both the Physics and Control sections.

    Here's the link:
     
  16. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    1,454
    Thanks very much for preparing the repro. lol I guess you weren't aiming for the comic version! We're investigating and hope to have a solution for you're scenario in the next few days.
     
  17. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    1,454
    We have added a couple of additional options which should work for your scenario. If you PM me with your email address and Unity invoice number I can send you a patch.
     
  18. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    1,454
    Supported Unity Versions

    The next release of Sci-Fi Ship Controller will support Unity 2017.4.6f1 to 2019.3.x.

    NOTE: Unity no longer supports versions older than 2017.4 LTS.

    We will also endeavour to fix any issues that people see in 2020.x alpha/beta. Currently we have no outstanding issues with U2020.1.0a8 and SSC 1.0.3.
     
  19. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    1,454
    AI System Info Update

    As you may know, the next major release of Sci-Fi Ship Controller will include a Ship AI system. This will enable you to control friendly and enemy ships.

    We are currently working on and testing a number of typical scenarios. For example, you might want to have some ships fly to an enemy base and attack any enemy craft or fighters they encounter, while avoiding obstacles.

    Please let us know if you have any scenarios that would benefit your gameplay.
     
  20. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    1,454
    Location and Path Editor and API

    Coming in the next release is a Location and Path Editor. This system will enable you to identify positions in your game where, for example, ships could fly to. And like all things in Sci-Fi Ship Controller, it is backed up by a runtime API.

    upload_2019-11-13_20-6-38.png

    A Location is a world space position without a game object which can be used by ships in your game. Examples could be:
    • Enemy Base
    • Friendly Base
    • Target location
    • Route marker
    • Ship spawn point or destination
     
    eaque likes this.
  21. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    1,454
    DOTS with U2019.x

    In the current version of Sci-Fi Ship Controller (1.0.4) we support the use of DOTS (Unity's Data Oriented Technology Stack) with Projectiles. This allows you to have hundreds or thousands of projectiles in your scene at one time with minimal impact on performance.

    For Unity 2019.1 and 2019.2 the following package combination has been tested:

    Entities 0.0.12 preview 33, Hybrid Renderer 0.0.1 preview 13 and Burst 1.0.0

    OR

    Entities 0.1.1 preview, Hybrid Renderer 0.1.1 preview and Burst 1.1.2

    In the next release of SSC (version 1.0.5) we'll be adding support for Unity 2019.3 and the following package version combination:
    • Entities 0.2.0-preview.13
    • Hybrid Renderer 0.2.0-preview.13
    • Burst 1.1.2
    If you would like to use DOTS with Projectiles in U2019.3 before Sci-Fi Ship Controller 1.0.5 is released, please let us know.
     
  22. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    1,454
    Playable Demo

    Although there are a number of playable demos included in Sci-Fi Ship controller, you may want to try it for yourself. A simple example, is the City Demo scene set up with a single ship controlled using the mouse and the WS keys.

    This setup uses Unity's new Input System and the built-in SSC Player Input Module.

    Go to our website, scroll to the bottom and download the zipped Windows 10 standalone player. The first time you run it you may receive a notice that it is from an unknown publisher. This is because it is an unsigned executable.

    ssc_playable.png
     
  23. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    1,454
    Navigating through the asteroid field in the next version of Sci-Fi Ship Controller

    asteroidfield1.png
    Imagine your ships doing this. It's also pretty easy to swap out the asteroids with your asteroid/space junk models.

    asteroidfield2.png
     
  24. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    1,454
    Version 1.0.5 is now available in the asset store.
     
  25. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    1,454
    New Path Features are Coming

    If you are wondering how complex a path can be created with Sci-Fi Ship Controller's path feature, I'll let you be the judge.

    upload_2019-12-9_15-46-6.png

    In making preparations for the AI system (coming soon) we needed a path editor. In-house, we also needed an easy way of transferring path settings and locations between team members. So, we added JSON input/export support. It's super fast and really easy to use. It also works with network shares if you have a LAN in your office.

    Currently you can race around the above demo scene circuit. But what you really want to do is race against AI opponents...
     
  26. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    1,454
    We have a big roadmap of features we'd like to bring to Sci-Fi Ship Controller. If you have any suggestions on what you'd like to see in SSC please let us know.

    We generally prioritise features that are being implemented in active game projects.
     
  27. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    1,454
    R&D, DOTS, and Unity.Physics

    We continue to put a lot of effort into Research & Development (R&D) for Sci-Fi Ship Controller. We strive for higher performance while solving common game development problems. One area is with the new Unity.Physics system that works in conjunction with other Unity Data-Orientated Technology System (DOTS) components.

    If you have plans to develop hybrid games with Sci-Fi Ship Controller and DOTS please let us know so that it can help shape our R&D activities.
     
  28. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    1,454
    Coming in Sci-Fi Ship Controller

    We've made great progress on our Ship AI system which will be in the next major release of SSC. Here is a sneak preview of what the Ship AI Input Module will look like. It will continue to be refined as we approach the release.

    upload_2019-12-19_14-52-1.png

    100% controllable through APIs, it also has an in-editor Debug Mode which permits you to see:
    • The current state of the ship (e.g. Dogfight, MoveTo etc.)
    • The assigned target (e.g. another Ship, a Path, a Location, or a vector3 position)
     
  29. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    1,454
    Here is the new Ship AI system in action. All these ships are being controlled by a Ship AI Input Module. The lead ship is following a path while being pursued by the other ships.

    AI ships need to avoid asteroids, while evading others or attacking the enemy.



    Sci-Fi Ship Controller customers can get early access to the Ship AI system through our beta program. Private message me with your name, email address, and Unity invoice number to join the program.
     
  30. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    1,454
    ANNOUNCEMENT - AI SYSTEM

    The culmination of many months of development and testing has resulted in the first release of our advanced, extendible Ship AI system.

    This is included with v1.1.0 of Sci-Fi Ship Controller. It should be in the Asset Store soon.

    You can see it in action in the Asteroids demo video in the previous post. The scene used to create this is included with SSC. The City demo scene includes a mock battle which uses the Ship AI system.

    We’ve added AI ships to the Anti-Gravity Racer so that you can see how good you are against them.

    We are working on a simple game built on top of the anti-gravity racer demo scene which will soon be available to download and play.
     
  31. cassius

    cassius

    Joined:
    Aug 5, 2012
    Posts:
    29
    How do I limit the speed that the player's ship can move at? It seems like the player continually accelerates if the "gas" is pushed and the only limiting factor is medium density (air pressure?).
     
  32. Dave_2000

    Dave_2000

    Joined:
    Oct 17, 2015
    Posts:
    51
    You can use medium density to control the top speed, but as you say this will not only affect the top speed in the forwards direction but also the air resistance in every direction. Typically you want to change the Drag Z Coefficient (a multiplier for the drag in the z-direction: forwards and backwards). To lower the top speed, increase it; to increase the top speed, decrease it.
     
  33. cassius

    cassius

    Joined:
    Aug 5, 2012
    Posts:
    29
    Thanks @Dave_2000. Perhaps I should be more specific about the end result I'm looking for as I realize my initial question was only part of the problem.

    I need a way for the player to be able to accelerate to their top speed within about 1 second. Increasing the "Max Thrust" to something very big gives me the quick acceleration I need, but doing that also means the top speed increases way past what I need. As an example, imagine a car with a top speed of 100kph with enough power to do 0-100kph in 1 second (very arcade-like). Do you know if there's any way to achieve that kid of result with this system? I've already managed to get the brakes where I need, but not acceleration.
     
  34. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    1,454
    What is your setup for Mass (Physics tab), Thrusters (forwards), and Drag Z Coefficient (Aero tab)? Maybe you have made the forwards thruster(s) so huge that cranking Drag Z Coefficient all the way up to 2 has no noticeable effect.
     
  35. cassius

    cassius

    Joined:
    Aug 5, 2012
    Posts:
    29
    Thanks @sstrong.

    My Mass is set to 5000, my Forward Thruster is set to 25 (in Z direction), and my Drag Z Coefficient is set to 0.01. Medium Density is at 1.293.

    However regardless of whatever settings I current have, is what I mentioned above about speed limit and (short) time it takes to hit that speed possible with this system?
     
  36. Dave_2000

    Dave_2000

    Joined:
    Oct 17, 2015
    Posts:
    51
    It should be possible to get pretty much any speed/acceleration combination, you just need to tweak the mass, forward thruster force and the drag z coefficient (typically you'll want to use the arcade setup and disable drag moments in the aero tab).

    Not sure if this is what you actual wanted, but I went with the example you gave of a ship with a top speed of 100 km/h and a 0-100 time of 1 second. You can achieve this with the following:

    - Mass of 50
    - Max thrust of 3
    - Drag Z coefficient of 1.7
    - Medium density of 1.293 (the same as on Earth)

    This gives a ship with a top speed of 100 km/h and a 0-100 time of 1.2 seconds.

    To get this, I first tweaked the drag z coefficient and max thrust values to give roughly the top speed I wanted (100 km/h). Then I changed the mass to give the correct acceleration, and finally re-tweaked the drag to fix any changes to the top speed that occurred as a result of changing the mass.

    The only issue I can think of for this is that you might want a more realistic mass value (mainly to deal with collisions). For this setup it needs to be set unrealistically low since such a high acceleration and such a low top speed isn't realistic behaviour (I assume since you are aiming for more of an arcade-style feel). If you do need the mass to be a more realistic value, try the following approach instead:

    First, set your mass to whatever value you want it to be (I set it to 1000). Preferably this should still be a fairly low value, so use whatever you think you can get away with in your game. Then, tweak your forward thruster value to whatever is required to get the desired acceleration (for me, I was still trying to achieve the 0-100 km/h in one second target, and the value that worked for me was 30). After that, adjust the drag z coefficient and the medium density until you get your required top speed (I got a drag z coefficient of 1 and a medium density of 25). Note that for this approach, you'll probably want to set your brake component to ignore the medium density (it's at the bottom of the aero tab). Once you've set these values, you'll probably need to go back and adjust your max thrust to get back the acceleration you lost (I had to adjust it to 45). From this point you'll be pretty close to what you need, so just keep tweaking the max thrust and the medium density until you get what you want.

    My final values were:

    Top speed: 102 km/h
    0-100: 1.2 seconds

    Mass: 1000
    Max Thrust: 48
    Drag Z Coefficient: 1
    Medium Density: 34

    Hopefully one of the approaches above should work for you.
     
  37. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    1,454
    Sci-Fi Ship Controller Version 1.1.1 Beta 1.

    Here is what is currently contained in the next version. Current customers can get access to pre-release versions via our Beta Program.

    [NEW] Projectiles with DOTS enabled, can hit Entities with a PhysicsCollider
    [NEW] Ship AI API - SSCMath.FindClosestPointOnPath when previous point on path is unknown
    [NEW] Ship API - EnableShip and DisableShip methods
    [NEW] Camera API - EnableCamera and DisableCamera methods
    [IMPROVED] ShipAIInputModule - Ship Speed in km/h available in Debug mode in the editor
    [IMPROVED] PlayerInputModule - Ship Speed in km/h available in Debug mode in the editor
     
  38. cassius

    cassius

    Joined:
    Aug 5, 2012
    Posts:
    29
    @Dave_2000 Thanks so much for the excellent support. These values (both sets) work perfectly for what I'm looking for. I'm glad that the system supports this kind of approach as well - it's flexible.

    I think originally I didn't end up tweaking the Drag Z Coefficient enough to get the results I wanted on my own. I now also know which method to use if I need to tweak the desired end-goal too thanks to your instructions above! :) I've noticed the two "IMPROVED" options in @sstrong's last post too.

    Thanks for the help!
     
    sstrong likes this.
  39. Dave_2000

    Dave_2000

    Joined:
    Oct 17, 2015
    Posts:
    51
    AI Post #1: Getting Started With Ship AI

    Hello again!

    You might have heard that in the last version, we added a new AI system to Sci-Fi Ship Controller, allowing you to create AI-controlled ships. We’ve been working hard the past few months on developing this new system, and we’re excited to show what it can do. So, over time, I’ll be posting some stuff on the forum (of which this post will be the first) about what this new system can do. Today’s post will show how you can quickly and easily get started using AI in Sci-Fi Ship Controller.

    To use the new AI system, you need to add the Ship AI Input Module to a ship. You can do this by clicking “Add Component”, then navigating to “Sci-Fi Ship Controller” -> “Ship AI Input Module”. Once you’ve added the module, you’ll also want to create a new script of your own and add it to the ship. This script will be used to tell the AI ship what to do.

    Below is an example script that shows how you can write a simple AI to attack an enemy ship.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. // Use the Sci-Fi Ship Controller namespace to get access to the API
    5. using SciFiShipController;
    6.  
    7. public class AIExample : MonoBehaviour {
    8.  
    9.     // An enemy ship for us to attack - this is selectable in the editor
    10.     public ShipControlModule enemyShip;
    11.  
    12.     private ShipAIInputModule shipAIInputModule;
    13.  
    14.     // Use this for initialization
    15.     void Awake ()
    16.     {
    17.         // Get a reference to the Ship AI Input Module attached to this ship
    18.         shipAIInputModule = GetComponent<ShipAIInputModule>();
    19.         // Initialise the ship AI (if it hasn't been initialised already)
    20.         shipAIInputModule.Initialise();
    21.  
    22.         // Set the AI's current state to the "dogfight" state
    23.         // This state only takes the input TargetShip
    24.         shipAIInputModule.SetState(AIState.dogfightStateID);
    25.         // Set the target ship for the AI to attack as the enemy ship we declared as a public variable
    26.         shipAIInputModule.AssignTargetShip(enemyShip);
    27.     }
    28. }

    The first important thing you’ll want to do in your AI scripts is use the Sci-Fi Ship Controller namespace – this gives you access to our API.

    Code (CSharp):
    1. // Use the Sci-Fi Ship Controller namespace to get access to the API
    2. using SciFiShipController;
    Next, you’ll need to get a reference to the ship AI input module (so that you can send commands to it) and make sure that it is initialised. The following two lines are ones you’ll likely want to include in all of your AI scripts.

    Code (CSharp):
    1. // Get a reference to the Ship AI Input Module attached to this ship
    2. shipAIInputModule = GetComponent<ShipAIInputModule>();
    3. // Initialise the ship AI (if it hasn't been initialised already)
    4. shipAIInputModule.Initialise();
    Finally, it’s time to make the AI ship do something! First, we need to set the state of the AI ship. States specify a particular goal for an AI ship. In this case, we are going to assign the dogfight state (one of the default states that comes with Sci-Fi Ship Controller). This state tells the ship to try and attack a specified enemy ship, while at the same time making sure not to be shot down itself. The following lines set the AI ship to the dogfight state, and then assign the enemy ship as the target ship:

    Code (CSharp):
    1. // Set the AI's current state to the "dogfight" state
    2. // This state only takes the input TargetShip
    3. shipAIInputModule.SetState(AIState.dogfightStateID);
    4. // Set the target ship for the AI to attack as the enemy ship we declared as a public variable
    5. shipAIInputModule.AssignTargetShip(enemyShip);
    And that’s it! That’s all you need to get a basic AI ship working in Sci-Fi Ship Controller. Over the weeks to come, I’ll be doing a few more posts like this, showing the features of the new AI system in more detail. For more information, you can also look at our manual, which goes over the features in detail.

    AI Post #2: https://forum.unity.com/threads/rel...-playable-demos-ai.594448/page-2#post-5399064
    AI Post #3: https://forum.unity.com/threads/rel...-playable-demos-ai.594448/page-3#post-5456418
     
    Last edited: Feb 8, 2020
  40. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    1,454
    Damage and Health (API)

    While working on a small demo game that uses Sci-Fi Ship Controller, we came across a scenario where instead of taking damage or resetting health we wanted to add some health to a ship.

    In the game we have some small PowerUp orbs that a player can fly through to top up their health.

    upload_2020-1-16_10-11-5.png

    We could update the health of a region directly but that gets more complex when shielding is enabled. If the Damage Model is Progressive or Localised, then adding health will take more lines of code.
    Code (CSharp):
    1. shipControlModule.shipInstance.mainDamageRegion.Health += 20f;
    2. // or
    3. shipControlModule.shipInstance.mainDamageRegion.ShieldHealth += 10f;
    In SSC version 1.1.1 or newer, you will be able to use our API to add health to a ship. If any components like thrusters, wings, control surfaces, or weapons have reduced health, they will be updated too.

    When the Damage Model is Simple or Progressive:
    Code (CSharp):
    1. // Add 25 health and update the shield if we get to the max amount of health
    2. shipControlModule.shipInstance.AddHealth(25f, true);
    When the Damage Model is Localised:
    Code (CSharp):
    1. // Add 25 health and update the shield if we get to the max amount of health
    2. shipControlModule.shipInstance.AddHealth(mainDamageRegion, 25f, true);
    3.  
    4. // Add 10 health to the engines region of the ship and update the health of any components in that region.
    5. shipControlModule.shipInstance.AddHealth(mycustomEngineDamageRegion, 10f, false);
    6.  
     
  41. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    1,454
    Coming in Sci-Fi Ship Controller v1.1.1

    We are expanding our respawning capability. In v1.1 when a ship is destroyed it can be:
    • Not respawned
    • Respawned at its original (starting) position
    • Respawned at its last position (x seconds before being destroyed)
    • Respawned at a specified position
    99% of the time those options are great. But what if a ship becomes stuck and cannot move? The new “Stuck” feature provides a number of options.

    upload_2020-1-17_13-49-21.png

    Without being destroyed, you might want the ship to use the configured Respawning Mode like resume from where it was a few seconds before becoming stuck. Alternatively, you might want the ship to resume flying along a path from the closest point to where it became stuck.

    upload_2020-1-17_13-49-0.png

    However, like with many things in SSC, you can also write a custom method to deal with your scenario if you don’t like any of the above options. That’s what Invoke Callback does. You write a method in your code that take a ShipControlModule as a parameter. Then you tell SSC about your custom method. If that ship gets stuck, SSC calls your method and you decide what to do.
    Code (CSharp):
    1. public ShipControlModule myAIShip = null;
    2.  
    3. private void Start()
    4. {
    5.     if (myAIShip != null && myAIShip.shipInstance.stuckAction == Ship.StuckAction.InvokeCallback)
    6.     {
    7.         myAIShip.callbackOnStuck = MyCustomStuckAction;
    8.     }
    9. }
    10.  
    11. public void MyCustomStuckAction(ShipControlModule shipControlModule)
    12. {
    13.     if (shipControlModule != null && shipControlModule.IsInitialised)
    14.     {
    15.         // Take alternative action
    16.  
    17.         // Check to see if this is AI ship
    18.         ShipAIInputModule shipAIInputModule = shipControlModule.GetComponent<ShipAIInputModule>();
    19.         if (shipAIInputModule != null && shipAIInputModule.IsInitialised)
    20.         {
    21.             // Maybe assign a custom AIState to reverse away and take another route
    22.         }
    23.     }
    24. }
     
    Last edited: Jan 17, 2020
  42. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    1,454
    Playable Tech Demo Game

    AG SSC Racer is a small tech demo that shows what can be done with Sci-Fi Ship Controller. You can read more about it in this Unity Forum.
     
  43. Dave_2000

    Dave_2000

    Joined:
    Oct 17, 2015
    Posts:
    51
    AI Post #2: Changing Between States

    AI Post #1: https://forum.unity.com/threads/rel...-playable-demos-ai.594448/page-2#post-5368236

    Today I’ll be showing how you can use Sci-Fi Ship Controller to implement state-machine-like AI behaviour for ships. This is the second post in this series, so if you haven’t already read the first one, I’d recommend you read that first.

    In the last AI post, I gave an example of a script that initialised an AI ship and set it to the dogfight state. This type of script works well for an AI ship that will only ever perform one type of action (in that example attacking a ship), but what about the times when you need an AI ship to change its behaviour in response to what is happening in the game world?

    To achieve this, you need to be able to transition between states. Below is the same example script from before, but with an added update statement with state transition logic. This example script tells the ship to attack an enemy ship as before, then go back towards a home base position until the enemy ship respawns again.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. // Use the Sci-Fi Ship Controller namespace to get access to the API
    5. using SciFiShipController;
    6.  
    7. public class AIExample : MonoBehaviour {
    8.  
    9.     // An enemy ship for us to attack - this is selectable in the editor
    10.     public ShipControlModule enemyShip;
    11.     // A position to return to once we have destroyed the enemy ship - this is selectable in the editor
    12.     public Vector3 homeBasePosition = Vector3.zero;
    13.  
    14.     private ShipAIInputModule shipAIInputModule;
    15.  
    16.     // Use this for initialization
    17.     void Awake ()
    18.     {
    19.         // Get a reference to the Ship AI Input Module attached to this ship
    20.         shipAIInputModule = GetComponent<ShipAIInputModule>();
    21.         // Initialise the ship AI (if it hasn't been initialised already)
    22.         shipAIInputModule.Initialise();
    23.  
    24.         // Set the AI's current state to the "dogfight" state
    25.         // This state only takes the input TargetShip
    26.         shipAIInputModule.SetState(AIState.dogfightStateID);
    27.         // Set the target ship for the AI to attack as the enemy ship we declared as a public variable
    28.         shipAIInputModule.AssignTargetShip(enemyShip);
    29.     }
    30.  
    31.     // Update is called once per frame
    32.     void Update()
    33.     {
    34.         // First check which state the AI is currently in
    35.         int currentStateID = shipAIInputModule.GetState();
    36.         if (currentStateID == AIState.dogfightStateID)
    37.         {
    38.             // We are currently in the "dogfight" state
    39.             // If we have destroyed the enemy ship, we want to return to our home base
    40.             if (enemyShip.shipInstance.Destroyed())
    41.             {
    42.                 // Set the AI's current state to the "move to" state
    43.                 shipAIInputModule.SetState(AIState.moveToStateID);
    44.                 // Set the target position to the position of our home base
    45.                 shipAIInputModule.AssignTargetPosition(homeBasePosition);
    46.             }
    47.         }
    48.         else if (currentStateID == AIState.moveToStateID)
    49.         {
    50.             // We are currently in the "move to" state
    51.             // If the enemy ship is not destroyed (i.e. it has been respawned), we want to attack it
    52.             if (!enemyShip.shipInstance.Destroyed())
    53.             {
    54.                 // Set the AI's current state to the "dogfight" state
    55.                 shipAIInputModule.SetState(AIState.dogfightStateID);
    56.                 // Set the target ship to the enemy ship
    57.                 shipAIInputModule.AssignTargetShip(enemyShip);
    58.             }
    59.         }
    60.     }
    61. }
    At the start of the update statement, you can see an example of a typical way of implementing logic (similar to a Finite State Machine). At any given point in time, the ship can only be in one particular state, so we start by checking which state the ship is currently in using the GetState() method.

    Code (CSharp):
    1. // First check which state the AI is currently in
    2. int currentStateID = shipAIInputModule.GetState();
    This returns a state ID as an integer, which we can then compare to the default state IDs (in the if/else if statements) to determine which state we are currently in. In this example, there are two possible states we could be in: The dogfight state or the move to state. The code below is executed when we are in the dogfight state:

    Code (CSharp):
    1. // We are currently in the "dogfight" state
    2. // If we have destroyed the enemy ship, we want to return to our home base
    3. if (enemyShip.shipInstance.Destroyed())
    4. {
    5.     // Set the AI's current state to the "move to" state
    6.     shipAIInputModule.SetState(AIState.moveToStateID);
    7.     // Set the target position to the position of our home base
    8.     shipAIInputModule.AssignTargetPosition(homeBasePosition);
    9. }
    While in the dogfight state, we continuously check to see if the enemy ship has been destroyed. If it has, then we set the state to the move to state (as we now want to move towards our home base) using the SetState() method and then assign the position of our home base as the target position using the AssignTargetPosition() method.

    The code below is executed when we are in the move to state:

    Code (CSharp):
    1. // We are currently in the "move to" state
    2. // If the enemy ship is not destroyed (i.e. it has been respawned), we want to attack it
    3. if (!enemyShip.shipInstance.Destroyed())
    4. {
    5.     // Set the AI's current state to the "dogfight" state
    6.     shipAIInputModule.SetState(AIState.dogfightStateID);
    7.     // Set the target ship to the enemy ship
    8.     shipAIInputModule.AssignTargetShip(enemyShip);
    9. }
    While in the move to state, we again continuously check to see if the enemy ship has been destroyed. This time, however, we expect it to have been destroyed – instead we are now waiting to see when it says that it has not been destroyed, indicating that it has been respawned. When it has respawned, we set the state back to the dogfight state (as we want to attack the enemy ship) using the SetState() method and then assign the enemy ship as the target ship using the AssignTargetShip() method.

    From this example, you can see how it’s possible to change between states at runtime. In the next few AI posts, I’ll be explaining how you can use the default states (idle, move to and dogfight) in more detail.

    AI Post #3: https://forum.unity.com/threads/rel...-playable-demos-ai.594448/page-3#post-5456418
     
    Last edited: Feb 8, 2020
  44. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    1,454
    Controller Force Feedback

    Coming in Sci-Fi Ship Controller 1.1.1 is controller force feedback / rumble / vibration. This is configurable for player ships. It will work when using Unity's new Input System or the 3rd party Rewired asset.

    upload_2020-1-25_10-51-6.png

    When the ship receives damage, once configured, it automatically send rumble instructions to the gamepad or controller. This has been tested with Xbox One and Sony Dual Shock 4 controllers.

    The overall rumble strength is set in the Player Input Module (or via code). If you have your own script that sends input to the ship (rather than using our Player Input Module), we have a call-back delegate in ShipControlModule that will call your device rumble code.

    upload_2020-1-25_11-0-15.png
     
  45. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    1,454
    Input Sensitivity

    The legacy Unity input system gave developers the ability to control how quickly an input device responded and how quickly it snapped back to the neutral state.

    Sci-Fi Ship Controller v1.1.1 will contain an optional per-axis sensitivity and gravity setting in the Player Input Module. It will work with all supported input sources. Currently those sources include:
    • Direct Keyboard
    • Legacy Unity Input
    • New Unity Input System
    • Oculus API (for VR controllers)
    • Rewired
    • VIVE (for VR controllers)
     
  46. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    1,454
    Sci-Fi Ship Controller version 1.1.1

    This version should be in the asset store in the next few days.

    [NEW] Projectiles with DOTS enabled, can hit Entities with a PhysicsCollider
    [NEW] Ship AI API - SSCMath.FindClosestPointOnPath when previous point on path is unknown
    [NEW] Ship API - EnableShip, DisableShip, ResetShip, and AddHealth methods
    [NEW] Camera API - EnableCamera and DisableCamera methods
    [NEW] Rumble or force feedback to controllers with Unity (new) Input System or Rewired.
    [NEW] Take action if a ship becomes stuck (respawn on a path, use respawning mode or call your method).
    [NEW] Respawning Mode - added Respawn On Path option
    [NEW] PlayerInputModule - per axis sensitivity options
    [IMPROVED] ShipAIInputModule - Ship Speed in km/h available in Debug mode in the editor
    [IMPROVED] PlayerInputModule - Ship Speed in km/h available in Debug mode in the editor
    [IMPROVED] SampleShowShipHealth - disable raycast target on Text objects
    [IMPROVED] Faction Id and Squadron Id are now configurable from the Ship Control Module editor

    Update: This is now in the Asset Store
     
    Last edited: Jan 31, 2020
  47. Silvermurk

    Silvermurk

    Joined:
    Apr 29, 2016
    Posts:
    162
    I see you did it already in scripts, but commented out somewhy?
    Turret LOS or a Physics.IgnoreCollision would be great addition to turrets actually, so you won`t hit yourself by a gun that shoots throu you:)
    UPD and is there a way to set ship`s speed to 0 for a full stop from scripts?
     
    Last edited: Jan 30, 2020
  48. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    1,454
    Turret line-of-sight and range are on our roadmap. We are also working on a radar system which would be useful with say auto-firing turrets.

    You can set turrets to avoid firing at the ship it is on with the Min, Max XY angles.

    upload_2020-1-31_8-48-39.png

    Code (CSharp):
    1. ShipControlModule shipControlModule = null;
    2. ...
    3. if (shipControlModule != null) { shipControlModule.DisableShip(false); }
    4.  
    5. // later
    6. if (shipControlModule != null) { shipControlModule.EnableShip(false, true); }
    or
    Code (CSharp):
    1. if (shipControlModule != null && shipControlModule.IsInitialised)
    2. {
    3.     shipControlModule.ShipRigidbody.velocity = Vector3.zero;
    4.     shipControlModule.ShipRigidbody.angularVelocity = Vector3.zero;
    5. }
    The first version requires Sci-Fi Ship Controller v1.1.1 which was released yesterday.​
     
    Last edited: Jan 31, 2020
    Bartolomeus755 likes this.
  49. Silvermurk

    Silvermurk

    Joined:
    Apr 29, 2016
    Posts:
    162
    Stop works pretty fine, thanks)
    As for LOS - kind of weird to fix angles if you have more than one ship AI on scene - because they tend to shoot each other in the back)
    Point me please on script where turret logic is implemented? I found it yesterday and lost earlyer today after update to 1.1.1
    Also i`m makeing a auto-target system for turrets, will drop code here after LOS implementation:)
     
  50. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    1,454
    The fixed angles are to prevent you hitting the ship the turret is mounted on (not other ships). For example, you don't want the turret to say fire into the deck or at say the cockpit or bridge. You are correct, it won't prevent the turret from firing at another ship in the same squadron or fleet.
    In the DemoControlModule script we show how you can choose who to target. And yes line of sight and our radar system should further reduce the amount of code required to prevent friendly fire.
     
unityunity