Embers of Empire Update – AI Dynamic Navmesh / A Star Experiments

screen_12.08077

Ever since this summer I’ve been struggle to make my AI better. I have Behavior Trees in and really easy to debug logic now, but the path finding has become an issue. The AI stumbled across the age old robotics problem of escaping a concave obstacle. I added a big derelict alien space craft that is integral to the story and a super cool set piece to fight around and explore, but the AI acts like an idiot ramming itself into the structure with the current avoidance AI. The current avoidance works ok for smaller obstacles but when things go on for miles in one direction, path finding seems to be necessary. So, off to AI school I go again.

I looked into the new dynamic navmesh for Unity and its ability to be created on surfaces that don’t necessarily have to be horizontal. I thought I came up with a good hack, but it still doesn’t always work, and the dynamic building of individual navmeshes for lots of ships is going to be a problem when battles scale up. In the video below the agent doesn’t change its angle much, even tho I programmed it to do it and it was doing it a week ago… A great demonstration of how hacky and unreliable it is. It was an exciting idea tho, especially given all the off the shelf stuff you can use with the navmesh like steering and formations. Too bad..

Since I don’t really like how the navmesh system fails a lot and building the navmesh over and over is necessary and slow because you need to keep orienting the plane in different directions so the ship can move in 3D, I decided to start looking into other stuff. 3D A* was an obvious place to go, but A* is not super fast-especially in 3D over great distances. So, I am looking at a Jump Point A* where you can have a mesh of nodes, but you don’t have to traverse symetrical nodes and you can jump to ones where you need to make a decision. I am thinking of it as like a line of site type thing. If you don’t have a direct shot to the target, traverse through nav nodes that connect to create a clear path.

Currently I am working on ways of generating efficient node maps of my levels. I am thinking of using non-uniform cubes represented by a bounds object at runtime. When baking the navmesh info, the cube might start very big like 1km in volume and if it detects a collider within it, it will break into small cubes that test for colliders until you have some areas with finer navmesh data. This way the empty areas of the map would have fewer navnodes to traverse, but when a ship gets in close to an object they need to path find around the nav data will be more refined. This of course sounds great on paper, but I need to make sure I can generate such a thing without locking up Unity or making the player wait an hour for the next scene to load. If it works I think I can add some very cinematic dog fights and ship battles with the small craft dodging and weaving in and out of complex space stations or between capital ships.

Developer Log: Space Warfare: Infinite – Capital Ships and Turrets

I spent the weekend putting together a capital ship and its turrets. Its still a work in progress, but it is fun to have to play around with.

screen_20.71244

Capital Ship!
I built the capital ship model using Pro Builder. I’m still a true amatuer at modelling, but I am working on it. The ship is a carrier-type with a big fighter bay on the side. It’s about a kilometer in length, but you can only really tell if you put a 3rd person character on it and walked around. It seems like the trick is to put bunches of detail panels and sloped surfaces on it so it doesn’t look like a flying cube. I am using games

like Freespace 2 as a reference since the ships were boxy but people still liked them. Once I get some nice models together, I will explore real texturing. The current carrier isn’t going to be in the finished game – at least not the model in its current form. The main goal was to get something giant to fly around and fight against that had a killer amount of turrets. Ta -da !

screen_50.51213

Having the cap ship, tho, gives me lots of directions to go. It’s be cool to have the player fly out of a fighter bay tunnel at the start of a battle. I have an idea for smaller gun boats that would be a much smaller cap ship with a big gun and a pd. They’s have less armor, but would be a bit more maneuverable than big stuff. They’d be used in groups to attack big

ger Battleships by attacking from different angles and things to overwhelm defenses. Going one-on-one with a battleship would be a big problem since a big gun might take it out in one hit, but a group could score a bunch of hits while a big gun can only focus fire on one target.

I want to get AI together that will allow the cap ship to maneuver. Once that happens, a second capital ship so that they can fight each other. The current one would have to have AI that would make it find an average waypoint in the middle of the action so it can get in there and mix it up with fighters. Or, it will need AI that can chart a course along the side of another cap to do a flyby. If all caps follow the current gun load out a dive and attack would be a good strategy since a caps guns are on top mostly, so getting under the enemy will offer a passing attack while not getting exposed to the bigger guns on top.

Also there will be at least one cap ship with a giant trench in the middle leading to some sort of highly explosive power core. It will be the only cap ship that a fighter might be able to take out on their own.

Turrets!
The turrets rotate and look up and down to target enemies. Currently they are sort of Point Defense guns, but I am also going to add anti-capital ship guns, beam weapons and missiles. The model for the turret is really for a big anti-cap gun.

screen_112.2582

My basic thoughts are that all guns on a cap ship should be on a turret since the ship can maneuver as simply as a fighter. Big anti-cap ship guns will rotate slowest, but pack a big punch. Currently, if a fighter is unlucky enough to get hit by a anti-cap projectile its instant explosion.  Big guns will prioritize other big ships that aren’t zipping around. Point Defense (PD) guns will track and take out fighters and missiles that get too close. Currently each turret has its own targeting AI. I hope to also add a targeting list function for some guns like PD and high-fire rate missile launchers so that they can move briskly between many targets. In a combat mission against Capital Ships, the main goal of fighters is to take out the PDs and other guns to make way for missiles to take out the ship. I am thinking some classes of cap ship will have strong enough armor that standard cannons on fighters won’t do any damage at all.

Dev Log: Space Warfare Infinite – Using Unity 4.6 UI for the HUD

 

The Unity 4.6 UI is really quite easy to use and it does not really on OnGui calls! I am adding some Data screens for the ship, just not sure what to put in there! Targeting info and ship status seem like the obvious choices. I like that you can make it look 3D so it feels like they are projected on the screen.

screen_70.66354

 

I like the immersiveness of cockpits, but I don’t like how they obscure your view of the action. I want players to be able to see the game and see what they are doing. I stared at the Privateer cockpit for a long time but that doesn’t mean it was the best way to see the game… I think I like the Elite method because its so open, but I like Star Citizen’s info panel design.

Key Features:

  • Better crosshair
  • Radar
  • Targeting
  • Ship / Shield Status
  • Systems Status
  • Enemy Target Info
  • Ammo / Fuel Status
  • Distance to waypoint

Inspiration screenshots:

Elite-hud

Elite’s HUD

 

starcitizenhud

Star Citizen HUD

privhud

Privateer HUD -not enough view!

Dev Log: Space Warfare Infinite – New AI tricks, missiles for everyone! and Unity3D Bloom findings

screen_78.26921Over the past week I’ve been having a lot of fun with Space Wars, while also researching and reading about AI. (I also got a little sidetracked by trying to perfect the bloom image effect….)

AI

AI can make a game like Space Warfare pretty exciting. I plan on having some multiplayer aspects once I get the major systems together, but the focus of the game is really a single player experience at this point. Since that is the case, cool AI pilots who behave in interesting manners is important. My actual AI code at this point needs to be refactored because it is a big mess, but the things its doing already even without a really nice organized OO state machine are pretty fun. I plan in the future to build out more of a Playmaker-esque state machine for these guys but it’ll take some focus. Because of the behaviors of the AI, the game is becoming pretty fun to watch. It has the enemies turn and loop and barrel roll to escape or ambush each other.

Current states include Chase, Attack, Reposition / Flee. Within those states the ships are able to barrel roll in reaction to being hit as well as change target focus. My idea is that I want to have some base states like Attack and then have a bunch of maneuvers that can be employed by the pilots depending on their style/personality/status. I am looking into multiple temporary short range ‘waypoints’ to create maneuvers so that AI can do looks or spiral at another ship instead of go in a straight line.

Some of my research to me to the above really cool video from Star Citizen (disclaimer: I am one man, Star Citizen will always be cooler than my game…). It hints how they are thinking about AI and displays some quick shots of the Ai engine. I can’t afford to hire that Ai company but I like some of their approaches. One of the things they really focus on is collision avoidance which made me think – oh man I don’t have anything to collide with yet other than really small ships better get to work on that! Unity’s Nav Mesh seems out because its a 2D plane and not a big open space. I’m heading towards a raycasting set up for individual ships. I forsee it being a little costly so I might have to add some collision radius objects that trigger the raycast steering only when necessary. One video that seems to explain the basics is here: http://vimeo.com/9304844. Sadly the author seems to have disappeared from the internet and never continued the series.

Missiles

I’ve also implemented missiles into the game. They are basically have perfect tracting to the only way to not get hit is to accelerate long enough that they can’t catch up or have them hit or get hit by something. I am working on a few countermeasures like a ‘chaff’ like drop and perhaps flares. I know chaff is for radar, but I might make it a dual purpose item in this game. It just drops a bunch of chunks of metal behind the ship that can clog an enemy radar with blips or set off a guided missile if a chunk collides with it. The other balancing option I will add is the length of time the guidance system works. This will give the player the ability to outrun then dodge a missile over a range if the guidance cuts out early, but is still a threat if the ship remains on the same course.

When I have add the ability to upgrade, ships could by better missiles with longer range guidance systems to make them harder to shake. As it stands now, unless your opponent launches a missile from too far away, the likely outcome is an explosion. Its so likely that for the above video I needed to disable missiles just to show you the Ai fighting without immediately creaming each other with missiles. Also I wouldn’t be able to stay in one place and film for my that 10 seconds before getting hit myself.

Missiles are a powerful weapon. But I always feel they are underpowered in games. Perhaps I should make it a little more random – 10% chance of surviving a missile? Perhaps its time to add shields!? Also individual parts of ships might mean less instant kills if its not a direct hit.

Bloom

On the Bloom front… well the game is shiny now! Look at the before and after!

 

screen_306.4306

Before…

screen_11.3738

After…

Things I’ve learned so far… some Unity image effects may be added after every camera is rendered. This means that no matter what camera you add an effect to, everything is gonna get the effect. The bloom happened on all my cameras no matter what my order was or culling set ups were. I’ve tried it all…. If someone out there reads this and finds out a way to make my findings untrue, I would love to see the solution! Comment, twitter, email me!

The main problem I’ve had is that the really nice Space for Unity scenes were getting over exposed and washed out so that you couldn’t enjoy the scenery. Since the main thing I wanted blooming were the trails and lasers, I ended up really brightening the particle materials they were using and then turning up the ‘threshold’ setting on bloom so that everything doesn’t wash out. It sort of works. I like more glowing than less so I am happy where I am with the look. Sometimes I feel like almost Bloom alone makes the Unity Pro license worth it — just the cool factor.

Dev Log: Space Warfare Infinite Updates -Bloom and Ai

I know I should be working on my November game, but the prospect of being able to devote more time to Space Wars (As well as finding a real game name for it – Space Warfare Infinite?) has been too tempting! I will get back to my monthly project soon, but  in the mean time lets talk updates to Spacewars.

Bloom –

Bloom is all the rage. It’s the main reason to get Unity Pro from what I can tell. That and the profiler. But lighting effects take your game and put it in the pro category – at least with the looks. I’ve been trying a bunch of different post-processing effects, but standard bloom seems to be the best for making space object look interesting and making laser flash and glow. The battle now just seems more alive! The downside is that brighter backgrounds glow too much and look too bright. At the moment I am just letting it slide. I fooled around with the camera render orders and such but could never get the bloom to only effect lasers. So far it doesn’t seem possible for me. (I did see someone wrote a shader that keeps bloom from rendering on something. I might do something like that someday to fix the nebulas and other stuff I don’t want to glow).

screen_11.3738

Ai –

I’ve also been futzing with the Ai. I really want to write behaviors and more decision making. The current Ai chooses a random target from a list of enemies and then blindly charges. When in range they start firing. The other behaviors include: if they get hit a couple time in rapid succession, they will find a random waypoint to run off to; if they are attacking for more than a few seconds they will find a new way point to back off and then go back to it; if they get hit by a ship that is not their target a few times, they will switch targets and defend themselves.

Last night I changed a few things that annoyed me. First I added a lead object to each ship so that ai will aim just before the target thus leading their shots. Works well for moving objects.

I want to build a behavior where the Ai does flybys or other maneuvers that make sense. As I step towards that, I removed their ability to stop. It looked super dumb to see ships just floating in space taking shots. I just have them thrust at all times now. I also dropped their rotation speed from 20 to 1 which makes them curve a little more when flying – looks more natural. No more turning to the player in a blink! I also want to add a behavior when they are too close for more than a few seconds, find a nearby waypoint to go to before attacking again — the ai seems to get in close and then circle the target without being able to aim shots. They need to be able to get a new attack vector. The movement makes the game much cooler looking. Everything circling around with trails.

Ai Behaviors I am hoping to put in:

  • Rush pass / loop: Ship flies by target attacking as they pass then pulls up and executes loops to do another run on same strike vector
  • Flanking loop to hit target from side Circle to get around and behind target Go to waypoint
  • Patrol series of waypoints
  • Follow / Protect target
  • Follow / Copy target (attack its targets) Stand still – cap ships will prob do this alot Kamakazi ramming
  • Strafe side – get up to speed then rotate to aim guns at target let inertia carry ship along side target while unloading weapons… (currently not possible in way game handles ship flight… but this might be an effective attack for fighters against a cap ships PDS)
  • Preferred targets – weakest, injured, toughest, untouched, ranged, fighter, cap, midrange, auxilery, stationary, slowest, low shields, low armor, high shields, high armor, no ‘type’ gun, specific ship
  • Scanning / Sight Range- how far should awareness go? Should be increased by auxiliary scanning ships in fleet.
  • Use specialized component – Scanner Jammer, EMP, Cloaking,

Space Wars Team Battle Demo is Here

The month of September was devoted to experimenting with procedurally generated space areas, hyperspace jumping, and dog fighting AI.

The result is affectionately named Space Wars Team Battle Demo. The team means AI teammates, no online play for this one… yet. Technically, if you fly long enough you can arrive at the planets. The game will eventually feature some sort of landing, probably not seamless atmosphere flight as that is just magical to me.

screen_249.6802

There are also jump gates that are functional. Again they require flying far into space. They are glowing spheres. Hit one and you will jump to a new system. These will eventually link between systems in a way that makes sense. For now they are random… The main ‘game’ of this demo is just destroying the enemy fleet and then auto-jumping to the next round. It’s hard. Here is the link to the Webplayer (PC and Mac Coming soon)… Frame rate seems ok when I play it, but mileage may vary –should run real fast on the standalone build.

Tips:
On the web version – Right click and Go Fullscreen. This will allow the mouse to lock and give you the ability to use the right mouse button to do a barrel roll.

Here is a video of some gameplay:

Surprise – more work on Space Wars!

spacewarp

My September game of the month has been an exploration of procedural (kinda random) generation of star systems that players can travel to through jump points. I’ve been using Space for Unity Construction Kit which makes really pretty stuff even when I write code to completely randomize its elements. I haven’t done the math, but just to choose a random seed, if picks a random number between 1 and 5 million or something so there are at least 5 million variations of star systems I suppose. Some might be more interesting than others.

Here is a video:

Hope to have a demo online soon!

spacewarsfight

New Space Wars Build – Missiles, Single Player Mode, Bigger Cooler Map #1GAM

Screen Shot 2014-06-19 at 6.59.45 PM

Ok so here it is, I’ve been posting video of this work in progress so now you can play it!  Here is the link to Space Wars Net. 

It’s not perfect – missiles don’t really work in multiplayer because of targeting. I have to rewrite the way I handle missiles to get that to work. They work fine against AI enemies tho.

The controls have changed a little – F or Right Mouse for Missiles. Space or Left Mouse for lasers.  Mouse Look to steer. Q-E to strafe.

Update: On further testing – I think I made the multiplayer cooperative… can’t seem to hurt the other player due to the collision detection. Didn’t want players to blow themselves up with their own missiles. I will fix this in the next update. Perhaps I need to add a teams dialogue to the log in screen.

 

Dev Log: Space Wars now has missiles! And it’s pretty… #1GAM

Screen Shot 2014-06-17 at 10.50.58 PM

A little more progress this week – I’ve added in multiple cannons and missiles to the mix. The missiles involve targeting enemies which I made automatic by just aiming at them. Aiming puts a red box around the enemy that is currently being targeted. From their a missile will chase the target for a period of time usually resulting in a hit. I tried all sorts of ways of doing the missile trajectory and while big arcing ones looked cool, they resulted in lots of misses. So the current missiles are pretty vicious and accurate. Check out the video of some highlights…

Another added feature is I’ve included Space for Unity assets in the game. They are much cooler looking than my stuff and I picked it up a long time ago so it’s best I put it to some use. In adding the cool planets and nebulas, I also expanded the map to about 4000 square units. Seems big enough to explore now. The mini map is a little crammed but I have plans to make it a little more zoomed in and then have an expanded area map UI at some point.

I’ve noticed with some of my updates, I need to test again online since some of the effects only show up for one player. Also the enemies are super jumpy if you are not the server it seems…

I’ve also been trying to figure out an offline mode but the Photon directions are unclear how to implement it… 🙁

Space Wars Update – Video with Scores, Sound, Hit Points!

I’ve added better(?) AI, explosions, sound effects as well as hit points and a score to the game. It might be getting too complex for the webplayer soon. We may need to switch to stand alone PC/Mac downloads. Here is a link to the web version of Space Wars…

Rewatching the video, I notice the AI is doing a lot of spinning. I am still trying to figure out how to make the AI better, I’ve tried a lot of things. Sometimes it works great, sometimes it does random silly things while it works out its rotation. I plan to implement a waypoint patrol ai, a search ai, a follow/guard ai and a defend area ai soon… Those will be sooner rather than later. Further on I’d like to have goal oriented AI and preferred targets where AI will assess enemy ships and decide what is the most important target. Fighters set to skirmish mode will rate other fighters highly as potential targets, but other fighters whose mission is to destroy a space station or carrier might skip other fighters to prioritize travel and attack their main target. This will be important as ships diversify, we can have capital ships chasing every little fighter buzzing around them if there is an enemy cap ship pumping them full of lasers…

Also up for the AI will be factions so that some AI bots can be on the player’s team. Then the real space war will commence…