Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Games Massive 3d Space Battle Simulator - Obstacle Avoidance Preview

Discussion in 'Works In Progress - Archive' started by FirstTimeCreator, Feb 5, 2018.

  1. FirstTimeCreator

    FirstTimeCreator

    Joined:
    Sep 28, 2016
    Posts:
    768
    I am building a space sim sandbox gratuitous space battle simulator with a large number ships 4-600 ships with full obstacle avoidance and an AI commander giving orders to Squads of ships on two opposing teams.

    The player will be able to pilot fighter class ships, cruisers, destroyers and capital ships as well as traverse the capital ships and view the battle from the bridge.

    Capital ships are massive in scale and in this video I am demonstrating high velocity massive object obstacle avoidance viewed from the bridge of a super carrier capital ship (ship larger than a star destroyer).

    Yes these are models from Sketchup. I am not a modeler, I'm a programmer so I'm working with what I can get off of sketchup as far as models go. The systems I have designed are "drop in" so I can easily drop in any asset, setup a Grid for it's obstacle avoidance and assign a Pilot Agent and it's ready to go.








     
    Last edited: Feb 7, 2018
    RavenOfCode and JFI66 like this.
  2. FirstTimeCreator

    FirstTimeCreator

    Joined:
    Sep 28, 2016
    Posts:
    768
    HyperSpace Jump, Floating Origin, Duel Camera setup added.

     
  3. Steve-Tack

    Steve-Tack

    Joined:
    Mar 12, 2013
    Posts:
    1,240
    Would it be possible to post a video with a camera attached to one of the TIE fighters so that we can see more what's happening?

    The camera is moving around so much and the fighters so far away (and kind of dark), that it's hard to see what's going on in terms of obstacle avoidance.

    Obstacle avoidance in a dynamic 3D environment can be a tricky thing. Care to share in general what your approach is?

    In any case, thanks for sharing the videos!
     
  4. FirstTimeCreator

    FirstTimeCreator

    Joined:
    Sep 28, 2016
    Posts:
    768
    I am generating a Grid around the ships that is scaleable to any size ship, Then I am shooting line casts out to the grid points, its rather complicated but what happens is it looks for directions witthin the grid that have no collisions and adjusts its course in the direction of the non colliding grid point that is nearest to the target destination (within the grid around the ship).

    I am also applying a force to the ship in the opposing direction of the collision points on the grid based upon the distance of the ship to the colliding object within the linecast to the grid point around the ship.

    It is kind of hard to explain, perhaps I will show a demonstration video of the editor. There is a previous video I made that has DrawLine on my grid points on my channel that shows it detecting active collisions on the linecasts.

    Check out my previous videos I had some exterior views. The AO is still a work in progress but it is nearly there, only a few minor glitches that need to be addressed related to forces being applied.




     
  5. Steve-Tack

    Steve-Tack

    Joined:
    Mar 12, 2013
    Posts:
    1,240
    Hmm, that does sound rather complicated, and yeah, it's a little hard to picture. Looking forward to the video with the visualization.

    I've attempted some simple obstacle avoidance for a space game and it didn't go so well. If you Google what people have already done, you run into a lot of traditional steering behavior stuff, but what I find on that typically assumes you'll be directly setting an object's rotation and position. That doesn't play nice if you're using the physics engine. There's some fancy stuff you can do with PID controllers that can help though I think.

    What I have now is a very simple system where a ship shoots out a ray cast (scaled to the ship's forward velocity), and if it gets a hit, the ship simply pulls up for a half a second. So if it's still hitting on the next check, it keeps pulling up. It works fairly well given how lame that really is, but it's not going to scale to something like navigating a dense asteroid field or dealing with multiple capital ships like your videos.

    I came up with something (only on paper) where each asteroid or ship would have a simple radius value. Fighter ships would shoot a line cast to its current destination point, and if it gets a hit on something, it'd attempt to plot a 180 degree circular arc of some temporary waypoints for the ship to follow. The idea is that the arc would be scaled to that object's rough radius and it'd be shaped so that the ship could follow it around and get a clear path to its objective. Even if that worked, it could be pretty limited still.

    Sounds like your approach is much more sophisticated. Is that an idea you came up with on your own?

    Thanks again!
     
  6. FirstTimeCreator

    FirstTimeCreator

    Joined:
    Sep 28, 2016
    Posts:
    768
    I have made many attempts before solving it! this is like my 5th re-write/re-design from scratch. And I have been trying for like a year. I am not using the physics system for navigation. I am using it only to force-push ships away from objects in the opposing direction of the collision. I am using my grid system for navigation around collisions. I tried other methods that failed or were to difficult to program an integrate system into an AI controller. I failed many times before I had my eureka moment lol. I know for a fact my current designed will work extremely well and is easily integratable into navigation systems as well. This system will navigate around very complex geometry with a massive ship or a ship as small as a tie fighter and with current optimization systems i can run about 400 (fighters) in under 5MS response time on an i7. Capital ships take a larger grid and more performace but I estimate i can run at least 10 Massive capital ships per team, 20 destroyers and 15 cruisers plus about 150 fighters per team when i get around to doing the AI and weapons/targeting systems.
     
  7. FirstTimeCreator

    FirstTimeCreator

    Joined:
    Sep 28, 2016
    Posts:
    768
    Yes that is what my system will do, it will not only navigate static asteroid fields but MOVING asteroid fields!!!! YES BABY MOVING ASTEROIDS! Yes i tried it with few line casts but it doesn't work, the AO does not look natural/fluid and ships will get stuck in loops around large objects. It just does not scale and it definitely does not work for avoiding moving objects very well. I tried that method many times before I decided to build this complex grid system.

    You know what? Im going to add a MOVING asteroid field and have it navigate to a waypoint in the center of the field, then you will believe me! ;)

    Before I do that though im doing some work to the bridge, there are still 230 components and I need to reduce that, reduce draw calls and increase performance. I will do the astroid field though before I start on the LOD system for the interior of the ship.
     
    Last edited: Feb 6, 2018
  8. FirstTimeCreator

    FirstTimeCreator

    Joined:
    Sep 28, 2016
    Posts:
    768
    Yes, but what if something moves into the way of the ship as its plotting around, would you simply plot another set of arcs? That also would not be fluid and realist because the pilot "agent" of the ship would not be trying to take the shortest path around the object to it's destination.

    The goal of my project is to avoid any and all objects moving or not moving and take the shortest path around the Object or Objects to it's target. So that the pilots appear to have intelligence as opposed to looking like a repetitive computer. They navigate around objects similar to how a human would. IT doesn't necessarily know the shortest path around objects, instead it knows a path available that is closest to its target around the object and will attempt to take that path unless it becomes blocked, then it will simply plot around the current object. It also can detect objects in all directions around the ship, so it knows if something is behind it, or to the side, it wont attempt to path into something around it.

    egh how do I explain this, it detects all objects around it, not what is ahead of it. It sees available paths within the grid.

    I came up with the idea based upon a pathfinding system based upon grids. A*, I believe? I can't remember. The difference is my system only has a grid around each ship and uses linecasts, instead of a grid over the entire scene which contains data of object positions.

    I am having to rebake the light map, its going to take a while. After than I will setup a simple moving asteroid field in the path of the imperial space station and i will make a video from external view in the editor nad i will turn on DrawLines to give you a visual representation of what it is doing as far as linecasts go, of course its abit more complicated than just the linecasts detecting objects as far as the programming goes.
     
    Last edited: Feb 6, 2018
  9. FirstTimeCreator

    FirstTimeCreator

    Joined:
    Sep 28, 2016
    Posts:
    768
    Yes, my inspiration came from A* and previews attempts. I designed this system from scratch, all my code.

    The main thing was "I needed to see all around the ship" and the only thing optimal i could come up with is a generatable grid based upon parameters that are specific to the scale of the ship. Then I optimized it by only shooting line casts out in intervals, 1/20 frames for example and thus being able to run many many ships that have 25-50 linecasts per ship without much cpu overhead.

    Here is an early version of the grid system, I have made improvements since this video and fixed every glitch you see in this video in my current build:
     
    Last edited: Feb 6, 2018
    Steve-Tack likes this.
  10. MitchStan

    MitchStan

    Joined:
    Feb 26, 2007
    Posts:
    567
    Wow. Really cool stuff. Love watching the clips. Really enjoy your commentary. Keep it coming.
     
  11. Steve-Tack

    Steve-Tack

    Joined:
    Mar 12, 2013
    Posts:
    1,240
    Looking forward to that!

    Very impressive system you've got there. Progress on my own space game comes in fits and starts as I have hobby time. So far I've focused on creating the UI's and RPG gameplay systems like inventory management, weapons, etc instead of getting the most important thing working (engaging combat).

    My placeholder combat is functional, but has serious issues, so it's nice to see some other ideas! Once thing I did that works pretty well is when a ship is attacked, it will sometimes perform a random canned move. Like one of the canned moves is like in Battlestar Galactica where a ship cuts its thrust, flips end-for-end, and rolls 180 in one move, then hits full thrust again, changing direction quickly. It looks pretty cool, and some of the "evasive maneuvers" are even pretty effective. Another favorite is a funky corkscrew move involving the "up" thruster and rolling at the same time.

    Coincidentally, this asset just came out that supports obstacle avoidance and even PID controller driven AI:
    https://assetstore.unity.com/packages/templates/systems/space-combat-kit-108097
     
    Billy4184 likes this.
  12. Steve-Tack

    Steve-Tack

    Joined:
    Mar 12, 2013
    Posts:
    1,240
    Well yeah, that's part of why that idea stayed on paper, haha.

    Haha, this is seriously one of the coolest things ever.
     
  13. FirstTimeCreator

    FirstTimeCreator

    Joined:
    Sep 28, 2016
    Posts:
    768
    Yah, I would like to see it's AO, I doubt it is very sophisticated. My AO will literally work on an object the size of a DeathStar ;) I am uploading a new video soon, Add Pilot Actions: in UI and a small asteroid field.

    After some testing need to do some adjustments to AO system to get it to fly through the asteroid field more fluidly. Also I may add a system for setting the density of the field and having the ship go around the entire field depending on the density because even my AO wont pilot a ship through a field that the ship cant fit through so the pilot needs to be smart enough not to enter high density fields or fields with gaps to small for the ship it is piloting.
     
  14. Steve-Tack

    Steve-Tack

    Joined:
    Mar 12, 2013
    Posts:
    1,240
    Dumb question, but what's AO? Usually around here that'd be Ambient Occlusion or Ambient Obscurance. :)

    I'm guessing Obstacle Avoidance, but that'd be OA, right? :D
     
  15. FirstTimeCreator

    FirstTimeCreator

    Joined:
    Sep 28, 2016
    Posts:
    768
    Yah multi tasking lol, uploading a video and looking at the OA code to improve it as well as setting up plans for Asteroid fields to report it density to the pilot so the pilot knows it can enter the field or to OA around the entire field. This will be dependent upon the ship size and density of the field.

    I will have to design a field generator with a density control system. Fighters will be able to enter all fields. Destroyers, most fields and cruisers/capitals will probably be restricted from entering asteroid fields.

    I'm uploading a video now of it attempting to pilot through an asteroid field, it will be done in an hour. What I learned from that is I need a system of controls for entering fields because for example the Blockade Runner ship is extremely long and the gaps between roids narrow in comparison of it's length making it difficult for the AO to navigate it without a accidental collision. It does course correct it's self though if it does collide.

    I have prepared for this event though and can easily integrate the systems necessary to account for this.
     
  16. FirstTimeCreator

    FirstTimeCreator

    Joined:
    Sep 28, 2016
    Posts:
    768
     
    Steve-Tack likes this.
  17. Steve-Tack

    Steve-Tack

    Joined:
    Mar 12, 2013
    Posts:
    1,240
    Thanks for posting that! Very cool system.

    I checked out that asset for space combat, and the main gameplay demo is actually pretty impressive. It's focused more on small fighters, but you can watch as the AI flies in formation and navigates around an asteroid field and a space station and you can trigger enemies for them to fight. It looks like a VERY different approach. May or may not be as robust as being able to fly capital ships like yours, I don't know.

    Have you played Star Trek Bridge Crew? In single player you can order the AI to fly to a destination and it has kind of rudimentary obstacle avoidance. I imagine your system is actually more robust.
     
  18. FirstTimeCreator

    FirstTimeCreator

    Joined:
    Sep 28, 2016
    Posts:
    768
    Yes I have played it, yes my system is more robust ;),

    It is not designed for low end computers, I am optimizing but I am not targeting cookie cutter machines. i5+,GTX 550 will be the minimum specs to run bare minimum. i7 + 770+ / Titan recommended.

    More important that GPU is CPU in the case of this sandbox, the OA is on the heavy side especially with 400 ships even with optimizations, you need a decent machine.

    Since im doing this for fun and if I build a game, I still wont care about non-gaming rigs as my "sales" target. I'm not money hungry, I want to build a hi-fidelty game with fun and interesting game mechanics even if they have a high resource cost and require a gaming rig to run efficiently.

    I want something similiar to X3 rebirth as far as combat but with more fleet based strategy and perhaps even Galaxy Conquering Strategy. Could turn into a basic empire builder pretty easily once you have the fleet combat mechanics in place and design a galaxy of say 100 sectors each being their own scene. It gets a heck of alot more complicated at that point software wise but wont be to bad since there wont be multiplayer.. not unless I made money and hired a team of developers lol. Also im limited to models i can use for free, but at least i can easily drop any model in to replace the star wars models im using if I decided to use the platform for an actual game later.
     
    Last edited: Feb 7, 2018
  19. FirstTimeCreator

    FirstTimeCreator

    Joined:
    Sep 28, 2016
    Posts:
    768
    Better Recording Software!
     
    FMark92 and 00Fant like this.
  20. FMark92

    FMark92

    Joined:
    May 18, 2017
    Posts:
    1,244
    Is that f'in flobots in the background?
    Good taste, my man.
     
  21. 00Fant

    00Fant

    Joined:
    Mar 10, 2015
    Posts:
    131
    Looks very Good! Did u planed a Multiplayer too?
     
  22. FirstTimeCreator

    FirstTimeCreator

    Joined:
    Sep 28, 2016
    Posts:
    768
    Nope, I am only one person! Single player is my only option. I can install hooks for future multiplayer support but initially it will be a single player game. Think X3 with better visuals, more ships, more focused fleet based combat and empire building minus economy building. I do not think I will include an economy aspect to the game as it is more of an action Sci-fi strategy combat simulation.. not a "trading/economy" game.

    There will be lots of ships in each scene up to 400 so there will be no CPU overhead for an economy management system. The economy will be simple, Like Risk, each sector will give you certain resources each "Year" to spend on buying new ships and weapon upgrades and for station and defensive platform building.

    There will be AI Fleet Commanders, first and once i start on the empire section of the game there will be an Empire Leader AI.

    AI fleet commanders will have goals and attempt to exploit your weaknesses, and they will act within the same rules as the human player within the game. Purchasing ships and stations based upon its current resource pool, deploying them to the front lines to Fleet Commanders that are in most need or, are about to launch an attack and need additional fleet strength to overcome your defending fleet and stations.

    As a massively huge space sim fan that was disappointed in X Rebirth, I know exactly what I want to play and would be really really fun. A combination of a few games from 4x to Turn based strategy like "risk" in starcraft 2.

    All things in due time, I have some work left on the Object Avoidance System and environment systems before I start on weapons and targeting systems and THEN fleet commanders which give orders and change individual ships targets within their fleet. Multiple fleets will be possible for one team in the same scene/sector.
     
    Last edited: Feb 7, 2018
    00Fant likes this.
  23. FirstTimeCreator

    FirstTimeCreator

    Joined:
    Sep 28, 2016
    Posts:
    768
    After That, I will start on the Scene Loader for sectors and a procedural generation system for creating X number of sectors within a MAP similar to X3's sector map. Then Random procedural content for the sectors, Random Planets, Suns and orbits. Random Resource Generation for the players pool that occupies it, so the map will be different every game.
     
  24. FirstTimeCreator

    FirstTimeCreator

    Joined:
    Sep 28, 2016
    Posts:
    768
    Lol I went with flowbots in the first thing I ever created in unity a few years ago, a seamless planetary lander, man I was a noob compared to now but I really gave it a shot!

    It's a video never got around to uploading it to youtube:
    https://drive.google.com/open?id=0B5gBU0VVYsRIaE93a1JlQm83T0U
     
    FMark92 likes this.
  25. FirstTimeCreator

    FirstTimeCreator

    Joined:
    Sep 28, 2016
    Posts:
    768
  26. FirstTimeCreator

    FirstTimeCreator

    Joined:
    Sep 28, 2016
    Posts:
    768
    What do you guys think of disabling collisions and avoidance while in hyperjump ? I forsee alot of problems with it that might be unnecessary to solve. I can do a full blackout effect like in star wars hyperjump so you wouldnt see yourself flying through planets. This way i can have it jump right to waypoints without it stopping and having to go around planets and asteroid fields and anything else that might be in the way.
     
  27. MitchStan

    MitchStan

    Joined:
    Feb 26, 2007
    Posts:
    567
    Looks great, man. And all your models are done in sketchup? Incredible.

    Only problem is, it’s lonely in there. You need some crew members walking around doing stuff.
    :)
     
  28. FirstTimeCreator

    FirstTimeCreator

    Joined:
    Sep 28, 2016
    Posts:
    768
    Yes they are all sketchup models. I'm fluent in sketchup, can prep the models and make modifications as needed. I'm not a modeler though and dont really enjoy it or have the time to build complex models and prototype the game so sketchup models will have to do for the prototype. I can easily drop in legit models later for an actual game.

    I will get to that eventually for now im programming the systems that will interface with the officers on the ship, as you can see "pilot action" is the ship captain in the simple ui i setup. I'm going to add navigation, engineering and weapons officer which will report their actions to the gui. Later I can add models and tie them into that system if i wanted to add sounds on the models like the officers saying "we have arrived" or "ships damaged" or "abandon ship".

    I have alot of work to do before I get to doing a crew. I can do that pretty much at anytime later. Before I do the ships crew I need to do weapons systems, targeting systems and flush out a basic engineering controller.
     
  29. Billy4184

    Billy4184

    Joined:
    Jul 7, 2014
    Posts:
    5,984
    Hey, pretty cool videos you have there. I'm the creator of the asset @Steve-Tack mentioned. Basically my approach involves using a spherecast that's roughly the size of the ship and projecting it forward, and using the collision normal information to generate a temporary target vector. Nothing too fancy, but it works quite well for convex obstacles and will do for a lot of games - although there are still issues to address with very close obstacles etc.

    For a complex obstacle-filled environment (which is not really the case for most space games) I don't think there's an alternative to 3D A* or something similar to what you have there, where you're checking LOS to a grid of points in space. I didn't implement it for my kit because frankly I think it's overkill for most situations and I wanted to start with the basics and best possible performance. It would be nice to have a generic solver that worked for a wide range of situations though, so I may be working on an optimised 3D A* in the future (or some kind of pre-baked vector field).

    For your solution, I'd suggest generating a spline path between points to prevent a lot of dog-legging behaviour, there's a vid somewhere on my kit thread showing how much cooler things look when using splines.

    Keep up the good work!
     
  30. FirstTimeCreator

    FirstTimeCreator

    Joined:
    Sep 28, 2016
    Posts:
    768
    Hey, Thanks.

    I wasn't dogging your asset or anything I just assumed it was more simplified and designed just for small craft.
    I couldn't find a video on your OA system.

    Eh, spline path.. not sure about that because I intend on having 400 ships in a scene. That would add alot of overhead, so I need to make it work fluidly with my current system. It is close, just needs some tweaking and adjustments for certain collision scenarios and to take into account the "length" of ship was well because some capital ships are extremely long.

    It isnt overkill if you can make it work with 400 ships in a scene with a good response rate ;)

    My goal for it is to scale to any size ship and to fluidly avoid objects and attempt to take the shortest path around the object to its waypoint destination. I want the player to have that immersion when they see NPC ships flying around fluidly and seemingly intelligently.

    I admit there are some scenarios where ships will collide and cannot avoid objects and that is fine because that is actually realistic. There are scenarios where even a human pilot would crash.

    Accomplishing "Really Good" AO is the goal, doesnt have to be perfect. I want to move on to weapons and targeting systems for fighters/capital ships ;) and eventually the REALLY fun stuff AI controllers.
     
  31. FirstTimeCreator

    FirstTimeCreator

    Joined:
    Sep 28, 2016
    Posts:
    768
    Also I'm satisfied if it will run on my i5 testing machine with a 550GTX graphics card. This is the minimum specs im targeting.
     
  32. Billy4184

    Billy4184

    Joined:
    Jul 7, 2014
    Posts:
    5,984
    That's definitely good efficiency. For my kit, the bottleneck is not obstacle avoidance, but the physics, since all the ships are 100% physics-driven.

    Anyway, I'll be interested to see where you go with this. Always good to see more space games in the works!
     
  33. FirstTimeCreator

    FirstTimeCreator

    Joined:
    Sep 28, 2016
    Posts:
    768


    I am going to be moving this topic to a new thread, which will have a proper title and also a large written out detail of the game's intended mechanics for an alpha release, this way i can get better feed back. I will be releasing build downloads as soon as the ship interior is 100% finished so people can help me test by reporting MS/RS and system specs.
     
  34. FirstTimeCreator

    FirstTimeCreator

    Joined:
    Sep 28, 2016
    Posts:
    768