Space Strategy/Simulation/RTS WIP

update 2016-09:
Game and thread has been updated. Please follow me at “Interstellar: The Endless War”. Always interested in feedback in the Unity Forums!

/update

Everything is done in Unity, C#, Blender, Gimp, and Bfxr ← all free software. The models are derived from Shipyard V0.7 by greyoxide and heavily modified or are my own. I intend to use those as stand-ins until I can actually pay for better models. Also using Detonator package with small modifications at the moment.

Also, if anyone is interested in collaborating, PM me! http://forum.unity3d.com/threads/221005-Space-RTS-Strategic-Simulation-game-needs-your-help!

<<>>>>>><<<<<<<<>>>>>>

<<>>>>>><<<<<<<<>>>>>>

2014-03-03
Working on the GUIs

2014-01-20
Random Planet generating being implemented. Check out the end of the thread for more details.

2014-01-20
Updated the strategic map to include a working camera (needs to be tweaked) but the camera follows selected planets/etc. Also selection of units and GUI feedback implemented along with a rudimentary menu showing some game options.

2014-01-05
Beginning development of the strategic map. 100+ stars were created each with up to 10 planets, and each planet with up to 5 moons. Everything is randomly generated. Including sizes, axial rotation, and orbiting speeds. Obviously nothing is textured yet, but those will be auto generated as well!

2013-01-29
Space superiority fighters (FtSS) attack a Battlecruiser (BC). Subsystems are specifically targeted and destroyed causing fires and eventual explosion. A convex mesh collider is being used on the BC. Particle emitters are used for fire effects. Still have a lot of work to do on basic collision avoidance for the moving ships.

2013-01-27
Simple scene setup to show rudimentary AI of fighter class ships. Space superiority fighters (FtSS) and Escort fighters (FtEsct) battle it out in between two Battlecruisers (BC) with two Cargo Freighters (FrC) nearby. Notice missle launches, muzzle flashes, target tracking, and veering behavior. Randomized target selection of top priority targets.

2013-11-18
Simple scene to show the relative sizes and speeds of the different ships in play. Ships in scene range from Battleships to fighter sized. Also a space station is in the scene.

To give a better idea of what I’m aiming for. The game will consist mainly of two parts.

Strategic:
The Real time Strategic side where you decide what ships you want to build, what you want to research, what star systems you want to explore. Colonize planets and setup space based economies. You will train your crews, build and manage military, assign officers, etc, etc. This part of the game will be much more GUI and Map based. I don’t want to call it like a 4X game cause I want the crews, officers, ships to feel like they have real meaning. So a ship may exist in use throughout the whole game (not become obsolete in the next 5 turns). The game won’t be “epic” in scope ie star ruler or Master of Orion. Technology won’t progress from “the wheel” to “black-hole generating super planet destroying weapons”.

The intention is to make it a true strategic game where choices matter more than just building 1000000 ships and destroying a planet. What assets you bring to bear and the training of the people under your command will be what matters.

Real Time battles:

The Battle side of the game will what the videos represent. Once your fleet arrives at a destination, the strategic side will pause allowing you to fight it out on the battle map (which will feel huge/vast although not huge number of ships). Your fleets (along with cargo ships/fuel ships/troop transports) will engage enemies, try to board and capture ships and stations. Your military will use drop ships and try to conquer planet-side stations. Ships will need to fueled/reloaded/repaired/towed away/scuttled etc. Crews will abandon ship and need to be rescued. Jump troops will try to board enemy ships and your fighters will try to shoot them out of the sky (I think I’m building this mechanic next :slight_smile: ). Shooting at civilian transports or escape pods will be a war crime btw (hurt moral and hurt your population approval rating).

My goal is to make the game as realistic as possible but not tedious, so a lot of these things will be AI managed. (when your bombers are out of bombs, they will fly back to their motherships and re-arm. Your support ships will be automatically protected and maneuvered out of danger.) Each ship will have a role and each fleet will have objectives.

An example battle would be: Your fleet drops out of jump and your carriers immediatly launch escort fighters and patrol ships. A scout finds a mine field and begins to map a safe path around. An enemy patrol finds your scout and destroys it. You launch more scouts and patrols with heavy fighters trying to locate the enemy base while the enemy is trying to prevent you from encroaching, engaging in intermittent firefights. Finally you find the base. Your destroyers and battleships move at a fast speed to engage the base and destroy its capital ship support. But oops, you forgot to scout sector A-20, and now enemy cruisers are closing on your support ships and carriers. Do you press the attack? Retreat to defend your support ships? Order a general retreat and regrouping? If your admiral survives the battle, he probably won’t survive the court martial…

This looks really good! Looking forward to see what it becomes! Keep up the great work!

Thanks, appreciate it!

Space superiority fighters (FtSS) attack a Battlecruiser (BC). Subsystems are specifically targeted and destroyed causing fires and eventual explosion. A convex mesh collider is being used on the BC. Particle emitters are used for fire effects.

Still have a lot of work to do on basic collision avoidance for the moving ships.

Looking good so far! I’ve been doing some work on my own Sci-fi RTS/simulation thing and I’m a bit envious of how streamlined yours looks already. :stuck_out_tongue:

I’ve got some basic fighter management as well but collision avoidance is indeed tricky, especially when using physics-based flight. I’ll let you know what I get figured out, if you’d like. :slight_smile:

Good luck and I hope to try it out eventually!

thanks, appreciate it. Ironically,. I’m starting to think that I need to back off physics engine in order to get more realistic physics. Funny right? But getting things to move realistically seems easier without making everything a non kinematic rigidbody… …we’ll see how I feel a few months from now though…

looks groovy dude.

i share your space physics woes.

ha! i can see from your blog that you do. You’ve seem to solved a chuck of them though, I’d be curious to see how many agents you can add to that asteroid scene before you get bogged down. I 've added more than 50 agents but my performace gets crushed with all the instantiations (waypoints / ammo / explosions) that get generated. But the AI seems fairly smooth. Have you created any large fighter versus fighter scenes? I’d be interested to see a video of it if you have.

take it easy

Love the models so far, and the game looks pretty nice.

So I got some basic collision avoidance set up for my fighters, and by basic I mean BASIC. All they do is a spherecast and turn towards their negative velocity vector if the cast picks up something.

RaycastHit collRayHit;
// collAvoidPriority just makes the scan distance bigger, but I want to make it based off of kinematic equations
//so that the ships get a more accurate reading on when they should start slowing down
float scanDist = Mathf.Pow(rigidbody.velocity.magnitude, 2)*Mathf.Pow(collAvoidPriority, 2);
if(Physics.SphereCast(new Ray(transform.position, rigidbody.velocity), collisionAvoidanceScanSize, out collRayHit, scanDist)  collRayHit.collider != this.collider) {
	//RotaCalc is my rotation computation script for fighters and missiles and pretty much anything
	rotCal.calcSet = RotaCalc.calcType.negVel; 
}

It’s tricky to tune this correctly, but then I also plan on adding a check against the normal of the collider picked up by the spherecast and then make a decision about which direction to thrust (towards negative velocity or normal to the collider’s surface depending on Vector3.Dot(rigidbody.velocity, collider.normal)). I was working on a universal save/load system all day today so there was no time to really refine the collision avoidance.

Very nice! Very Homeworld ;D Will you be able to take control of an individual fighter or capital ship?

I haven’t setup combat yet, I’m trying to get the avoidance algorithm working consistently before I start adding combat behaviors. Have you looked at UnitySteer? I emailed some AI/pathfinding asset package devs and they didn’t really have any solutions for the 3d space scenario, just nudged me in the direction I was already going but Ricardo had some more concise advice and pointed to some specific scripts in UnitySteer that might help, if nothing else to get ideas from his methods. He seems to be able to instantiate just hooplah’s of agents without any issues.

Have you looked at UnitySteer

I tried unity steer and it seems to work great in 2d-ish world, but in 3d I was struggling with some (what i think is) gimbal lock Basically my ships would end up being perturbed into the +/- Y direction and then start doing death spirals into +/- Y direction infinitely. ( It’s actually quite an elegant death spiral. maybe I’ll post a vid). I think the problem was that all the calcs are using vectors.

Before I even tried Unity steer, I had tried building my own boid-like steering using quaternions but I put it aside. Maybe I’ll go back to that to avoid death spiraling. But Unity steer looked awesome otherwise. I might use the framework they setup.

Thats interesting approach. I guess my way is probably dumber… I’m using colliders on everything. Then each agent is keeping a list of all it’s nearby objects. Using the same exact system for targeting system basically.

Thats kind of unfortunate to hear about UnitySteer, would it be hard to butcher UnitySteer to use Quaternions instead - to avoid gimbal lock? I still plan to look into it.

Sounds like your implementation is more robust than mine, i’m flying kind of blind just trying to arbitrarily turn and look at some target point and rely on the raycast system to place that target in a safe location by bouncing vectors off of the obstacles. I thought about mixing in some node based pathing but I know its going to murder performance in congested areas.

If you have very few colliders and a lot of open space then its not such a staggering feat but I’m aiming for successful navigation through tight asteroid belts to pursue a target so I think our applications are a little different, but yours is much more fleshed out so far, seeing AI space combat in a work-in-progess state is juicy… (kinda makes me jelly…)

Thanks! appreciate it. I don’t think I want to create a “flight” simulator, so no, it won’t be a jump into the flight seat kinda game. But I think it is very useful (and neat) to attach the camera to the fighters. Helps a lot with the debugging. The game will be RTS style controls, so more like the “scene” view in the vid (the grey side of the videos). But I haven’t implemented camera controls yet :face_with_spiral_eyes:. I put more info about what the game will be like in the initial post.

Actually i think they are quite similiar, whether avoiding a bunch of asteroids or avoiding a bunch of ships! I personally am going to avoid a pathfinding/node-link style system [ mostly because I think I want collisions to happen :slight_smile: ] but a friend of mine mentioned something like a sphere casting system (I think he called it voxels) which would basically put a bunch a spheres into your nearby space and grow them till they hit something. Then you can get an accurate picture where there is a lot of space and where there is a little space, and even if there is a legit path from point A to point B.

I tried using colliders for my targeting system too, but it ended up being unreliable when the target for a ship was null and would take several seconds (very bad) to find a new target, shooting off tons of NullReferenceExceptions. What I have now is a GameObject.FindObjectsOfType() putting all flight computer-equipped objects into an array and choosing a new target based off of distance. It has a customizable refresh time so that it doesn’t refresh every frame and kill my computer.

I used a similar method for a ground-based RTS experiment with A* Pathfinding because the triggers on my drones weren’t picking up the resourceCache and resourceNode objects correctly, so I had to find a new way to do it. Once I figured that out, I just changed it to work with FlightComps for targeting (my SaveManager uses the same method to find ships to save). It’s still a little finicky at times, for example I get the occasional error when only one team of ships remains and they’re trying to find something to do, but in the end I find it’s much more effective than colliders. Granted, I still want to use triggers for some things (like ship-based turrets… maybe…) but they haven’t been that reliable for my uses thus far.

I too have tried UnitySteer for a very early version of my project, with my fighters setup as boids, but that was months ago and my coding skills were rudimentary at best. Even now I can’t imagine trying to modify their code to work the way I want it to operate. Writing your own steering code is the way to go, in my opinion. It gives the chance for ships to have a “human pilot” feel to them, especially if they hit something even while trying to avoid it. :slight_smile:

That is quite true, after all if there weren’t blackout/redout issues with G-forces then AI would just do circles to try to get behind each other, making quite uninteresting dogfights. Having some error and poor judgement is good for immersion, as long as it isn’t an outright stupid blunder.

All kinds of good ideas in here. Maybe I should just move forward with my AI and start adding basic combat behaviors and polish the broken segments later. I hadn’t even thought of using spherecast’s for some reason…

Unless moving forward requires fixing broken things, that’s a good plan. My combat is as simple as aiming towards the target and firing the weapons- the flight style of my ships alone is enough to make actually hitting the target a challenge, but it’s not such a challenge as to make a 6-on-6 dogfight take forever. It usually takes a couple minutes for one team to win (it’s typically team B, since their fighters are so much better :stuck_out_tongue: ), and missiles make that fight last even less time.

BTW, this is how the collision avoidance looks in my scene view:

The green box is the collider and the orange sphere is the radius used to check for potential collisions. The good thing about spherecasts over regular raycasts is that you have a bit of a buffer depending on how big you make the sphere.

Good luck with your AI, I tried one of your earlier builds with the space mines IIRC and I enjoyed it. :slight_smile: