Dev Log: Space Warfare: Infinite – Battle Editor, Projectile Pools, Bugs squashed, Unity 5 tutorial

It’s been a long week with lots of snow days to work on Space Warfare: Infinite. While I added some features, I have been spending a lot of time on optimizing and finding bugs.

screen_60.71658

Porting to Unity 5 – set-backs, opportunities
I converted my game over to Unity 5 only to find after many hours of fixing all my prefab connections and UI stuff as well as as many Red and Yellow warnings in the console that I could, that Unity 5 would not compile my game to stand-alone or when it did the game would be a black screen, a black screen with music or a the actual scene at 1 frame per second. Not good. I ended up starting a new Unity 5 project from scratch and began exporting component packages of my game as well as just importing assets one at a time. I figured as I developed I had lots of random scripts and tries at things that might be mucking up the code. Additionally I had a bunch of 3rd party stuff that I wasn’t using anymore or have pieces of but don’t need the whole thing. I left all that extra stuff behind. When I was done – although I am still bring in some non-essential or unfinished stuff – everything compiled and worked!! It was a bit of a wasted 8 hours, but I took the time to organize my code, make folders for everything, clean up the scene. In the end the project is more user friendly and easier to work with than before.

Here is a gameplay video of the latest build in action:

Start Menu and Unity 5 Tutorial

I made a new start menu! I put in place holder buttons and filled them with names for my aspirational game modes. Some day when all the buttons actually work, the game will be somewhere close to donish. I suppose there will be more to this menu and I need to build the sub menues like Options etc. Currently they take you to my test missions. I guess they are a kinda instant action more than a coherent campaign. The Instant Action button will someday take you to a menu of instant battle scenarios to select from as well as any user generated battles that were flagged as instant. The Campaign menu will have the list of selectable campaigns as well as the load and save functions.

This one has tooltips to explain the different modes and options when you hover over a button! If you can figure out a non-invasive way to explain stuff, I am all for it. I want people to be able to just play my game. (He says as he joins the time honored tradition of using every key on the keyboard). And generally you can just jump in with a 3 button mouse and WASD controls you can fly the ship and shoot at things. However, the game can also be pretty complicated as I add more and more systems. I want the player to be able to control all the things.

Screen Shot 2015-03-08 at 11.29.54 AM

 

I also made a video on how I did the tooltips for other Unity 5 game devs out there. Now that Unity 5 is super free, perhaps I should my more of this videos for my students and other folks.

Object Pooling for Projectiles

Was this a problem I had to fix? Who knows! Mike Geig told me in a video that it could increase my frames per second by 10! Why not give it a whirl. Also I know that instantiating something big sometimes stutters a computer and I don’t want that to happen. I’m working in more loading screens. There is now a loading screen for the beginning of a mission, but it loads so fast you don’t see it. But, you might soon as I want to instantiate all the missions ships at the very beginning during the loading phase rather than one at a time. Once I set that up, the ship initialization can be have – plus they build their object pools at the same time. So I need to do all this on the front behind the load screen – can’t have things pausing in the middle of the action so another ship can warp in.

screen_43.2535

Battle Editor
The battle editor is one of the main things I want to set my game apart from others. A major inspiration for what I am trying to accomplish in Space Warfare: Infinite is Gratuitous Space Battles. I love the giant fleet battles and wonder what its like to be that little fighter in the midst of it (or the capital ship commander for that matter). I also share Cliffsky’s love of explosions. Building a simple drag and drop battle editor toy box is a huge part of making this dream a reality. I want the game to basically be modible from the start. Growing up my favorite thing about some games was being able to build my own maps and missions. Before we had stuff like the Unity and Unreal engines, and you had to read the 2000 page Tricks of the Windows Game Programming Gurus and wade through pages of DirectX code to make a game, having a map editor or an easy modding tool was the best. I loved making Doom levels of my own. I loved building Starcraft maps to play–especially filling the map with tanks and bunkers lined up against each other. I had a great time making 3D studio worlds.

Anyway, now kids have Minecraft (and make whatever they want all the time) and the first question people ask you about any game you are making is: is it sandbox based and will there be crafting? The short answer is – yes you will get to fly to an asteroid, don your space suit and your intergalactic pick axe and mine cubes of ore to forge it with your bare hands into an Ion Cannon–all while being shot at by a heavy cruise with a rail gun aimed right at your flying refrigerator ship. Wait, no. The short answer is no. At least I think so. I plan to have miners in my game. But they will mainly be there to get blown up by pirates. You can just have the Ion cannon.  At the same time… I am building tool so that a player can add an item/ship/projectile/weapon to the game with a unique name, look and functionality. You just craft it in the Battle Editor and add it to your custom Campaign, mission, scenario, free play rather than in game while wearing your space suit.

Screen Shot 2015-03-07 at 11.27.04 PM

Currently the editor is not much to look at. You can select ships and drop them in the sector. Currently everything will be on the same plane –in game things fly in all directions though. The sector distance I settled on is 50 kilometers in every direct from center. I think this is ok based on floating point limitations (which is the data type used in the position vectors). From what I understand you can have 7 digits of accuracy using floating points. Since each unity is a meter I can get down to a 100th of a meter-known to the rest of the world as a centimeter. I guess I could go from  50000.00 to 99999.99 but 50k in game already seems pretty large for a battlefield and I want room on the edges so that if combat takes place at the 50km mark there is lots of room around it before float point errors occur. I can only see this happening with an AI going haywire and running in a straight line out into the distance and a very determined player with a lot of time on their hands chasing them.

The editor will eventually have the ability to add scripted events like Comm messages, ships jumping in at certain times, check points, objectives to complete or fail.

screen_161.825

Additionally, I envision that when you select to create a new battle you will be taken to a map of the universe first, allowing you to chose a system and then a sector of the system to use as the battlefield. At some point, when I player creates a new campaign, they will be able to generate a randomized universe or map out a custom one and then use that to build their battles. Each battle will be linked by a campaign editor which will be able to take into account objectives met/failed and choose branching paths.

In the near future, I want to get the basic place ships functions really working so you can save it and load different battle configurations in instant action. After that we will add controls over the more advanced events and objectives. Having a functional battle editing toy and a few default instant action missions will basically mean some sort of demo will be ready to send out to my pre-alpha testers.

Bug of Doom!
So I compiled my stand alone after rebuilding my entire project, everything awesome! Bugs destroyed. Let’s play this game… Game began crashing the moment a certain ship warps in on the 3rd play through only. I only noticed it after I built a stand-alone. My nightmares had returned. It was an insane bug. You could play a whole mission, no crash. You could restart on the start menu and play again. Nothing. But restart and play that third time and about 5 seconds in the screen freezes. Nooooo! I figured I was never going to get to build a stand-alone game in Unity 5. I spent an entire day debugging and finally pinned it down to using a static class for pilot names. I guess it creates a memory error after being reloaded (I believe statics stay in memory after a scene reloads). Since the game crashed, I could only watch my Unity Console up to the moment of the crash and if I was playing I couldn’t see it at all. I relied on the system console to read the debug.logs. I basically added debug.logs before and after every function call in the AI initialization until it became clear. I know Statics can be bad, but man, my game crashed because I wrote a dumb class to give my fighter pilots funny names.

screen_98.76686

On the plus side, before I figured all that out, I added garbage collection, making sure Invokes and Coroutines were stopped when the game reset. I tried to make the audio better. I began working on the object pooling. Lots of good coding practice came out of this nightmare. Sometimes you have to be tenacious as a programmer.

Little things:

  • Cool new music – and a music player that chooses a random track so I (and you) don’t hear the same song over and over again for the last year…oh wait that was before I added this feature. The music is techno western-ish, need more. If you read this and make electronic music for games and can make electronic/western music or just music that won’t clash too much with that and be good for epic space warfare and won’t charge me lots of money….send me a twitter msg. Brown Coats forever.
  • New yellow Power bar – gives you available power, all guns use a small amount, beams use a ton, engine thrusts have the green thrust reserve bar but can dip into the power after its gone. (or is this a huge thing?)
  • Bleep sound when a comm message appears or changes so you remember to look up and read the story
  • Made some fighter based lasers -will be continuous and pulse versions
  • Made the J.I.M. anti-missile turret for fighters (still need to import to the newest build though)
  • Added some anti-cap ship torpedoes – limited guidance, big punch if landed
  • The player now flies my fighter model for better or worse

Space Warfare: Infinite – Dev Log – Capital Ship Battles, Ship Switching, New Cameras, Unity 5

Sometimes it feels like not much has happened in the last week or two, but actually if I reflect back, Space Warfare: Infinite has made some pretty good progress.

screen_41.14206

Ship Switching

One of the key features of the ultimate vision of the game is in. It needs to be refined and tested, but the core functionality is there. (Meaning you can do it, but sometimes the game breaks…) You can now switch between ships in your fleet! You can be flying along fighting in your tiny fighter and then press a key and swap to a big capital ship destroyer. Fire off a few beam blasts and jump into another ship. The ship you left will keep flying and fighting as the AI takes over.

The ultimate idea is that you can choose to effect the outcome of the battle in all different capacities and see the battle from all different perspectives. Eventually you will be able to give some basic tactics at the beginning of the battle to each ship in your fleet and then during the fight you can issue commands – currently just in the Comm menu– but probably eventually in a little more RTS-ish like a holographic command screen on a command ship.

screen_99.05984

Capital Ship Control!

Another thing that wasn’t possible a week ago was capital ships doing anything other than sitting in one place and firing from their turrets. While that was cool, its not very practical for a giant flying behemoth covered in guns to sit in one place while fighter ships dance circles around its turrets. So now the AI is hooked up — cap ship specific AI maneuvers are still a work in progress — so the capital ships will fly around and slowly chasing things and try to hit them with the ‘big dumb guns’ on their bow while their turrets focus on whatever catches their attention.

screen_42.9131

Capital ships helped add a new feature to ships and AI – the idea of types and classes. Now AI can look for enemies in their own class size and choose to only attack those. What this means is that if a I set a big capital ship like a Destroyer to only attack other ‘Large’ class ships, it will not try to chase fighters and instead will try to aim its big guns at other big less nimble targets. The turrets currently run on their own AI so they do whatever they’ve been set to do. Fighter turrets look for fighters, anti-cap turrets aim at big ships, point defense targets incoming missiles. Eventually AI and the player will be able to command turrets to attack selected targets or get all turrets to focus fire. This will truly be the way to take down the bigger ships faster. The big ships have an absurd amount of armour and hull strength, but don’t actually last long when hit with powerful guns. Fighter cannons take more rounds than most fighters have and thats with every round hitting only one side of the armor.

Cameras and Controls

So not only do Capital Ships fly on their own, but now the player can control one too. At the moment this means you can fly it around, roll it so the turrets have a good angle to pick up targets, point it in a direction and fire a giant plasma cannon or a beam weapon from the front. Eventually more controls will come — like commanding all the turrets, launching fighters from carriers, commanding other ships from a bridge, launching nukes, managing shields and power.

Additionally, the capital ship controls made the need for new cameras to be added. Trying to fly a kilometer long skyscraper through a combat situation from a first-person or even a third-person perspective is somewhat difficult. A middle mouse button orbital camera was added so that you could get views from various angles around the ship as well as zoom out to see what is around. I’ve also added an FPS mouse look that puts you in the middle of your ship / or your cockpit on the fighter and allows you to look around and behind you. I am mapping these to the F1-12 keys like in Privateer and Wing Commander games. I have a bunch of directions plus the orbit and mouse look setup in there. The functionality is there, but I am still working to make it better.

screen_152.8223

Unity 5

I also upgraded to Unity 5 because I keep looking at the graphics advances, the new physics engine, and the frame rate boosts and just needed to make the jump. I thought the move would fix a turret issue I had where my turrets were spinning my ships – but I think the way I finally fixed it probably worked in Unity 4.6 as well. My problem involved wanted to have turrets (and other future stuff) be able to take their own damage and be targeted and destroyed. The turrets move but are children of another big damageable rigidbody thing as well. But I needed a collider and a rigidbody on the turrets so that hits would register on them. Every time I did this the turret or turrets would spin the ship, fly off the ship into space, stay on the ship but turn on their sides. Anyway, rumor has it you didn’t need a rigidbody on a collider in Unity 5, but that doesn’t seem to be true. I understand that now moving a static collider doesn’t result in a penalty, but I guess it wasn’t the same as my problem. Anyway, I figured out that if I turned my colliders into triggers on the turrets, they’d stop messing with my ships, stay in place and take damage. I don’t know if this is best practice but it works! I need to make sure other triggers are not included on the collision layer mask for projectiles, but other than that it works!

So while Unity 5 didn’t really solve my issue, it did speed up the game. I seem to be able to get more stuff going on the screen than before while still getting a decent FPS.

screen_32.11617

One downside was most of my scripts lost their inspector set variables and the UI doesn’t know where any of its components are. I’ve been slowly fixing it all, but things are a little scrappier at the moment. A few above screenshots have white boxes where UI is supposed to be, that was the most noticeable Unity 5 upgrade effect! It slowed work on other stuff down for sure. I am hoping tho that now that I am up and running with Unity 5, I can make use of the new shader and its better use of threading to keep the game fast and furious.

Space Warfare: Infinite – Dev Log – AI Dogfighting Maneuvers and Launch Tube

Part of last week and into the weekend has seen a lot of time devoted to reworking the AI. I also wanted to add some new visual elements and while I did not get around to modelling a bunch of capital ships, I did model a launch tube for the player to fly out of.

Launch Tube

launchtube

The launch tube is really just a mock up. It will get modeled in Blender someday in a more fleshed out way, but I wanted to add a more cinematic feel to the game play. It works! I have a whole idea for the first mission of the game and it will involve a FPS style run through the ship to the launch bay and then getting shot out into space. I won’t spoil too much, but lets just say my influences are books like The Lost Fleet, Old Man’s War, Armor and Starship Troopers. They all give a similar feel of a first battle against a superior force. I think it will be a rewarding intro if I can pull it off.

AI

I’ve been reworking the AI from a Switch/Case (I know, terrible) to a class based approach like the one on the Unify Wiki and the one described in Unity 4.x AI Programming — but with my own twist.

Screen Shot 2015-02-08 at 9.19.02 AM

I am starting with what they explain, but I am working on making it more modular so that I don’t have to write an base AIScript for every pilot style. I want to be able to drop behaviors and maneuvers onto a ship and have it fly a certain way. I am getting there. I’ve built a maneuver component that has the ship fly a pattern, the pattern is imported into the AI State at runtime. It’s still not exactly where I want, but it’s starting to work pretty well.

Once I perfect the way the pilots pull in the patterns, I will also be building in better decision making for the AI. I’ll build in which patterns are best for different situations offensive and defensive. Additionally I will be adding in cooperative moves and player commands to get assistance from wingmen. I’ve also got plans to start making AI adhere to the same targeting situations at the players so the player can lose an enemy etc.

screen_47.04968

After the dogfighting is passable, I will start working on getting the capital ships moving. They need to move differently than the fighters and small craft, but currently they just sit there and hope their turrets have something to aim at. It will be real cool when those things start to move.

Space Warfare: Infinite – Dev Log – All about Scanners and Target Damage

This past week I’ve been working on unifying the ship code and it is just about done. Now the player and AI ship code is shared completely with added scripts for the extra player functions like input and UI things.

screen_110.5652

The shared code means that now enemies can use all the components like different weapons and specials. This means more varied ships (of course I need new ship models) with different fighting styles. I also want to redesign the AI to incorporate the ability to switch to different weapons for different situations or employ countermeasures to stop missiles. I am getting close to feeling pretty good about the player systems (by no means done) to go back to focusing on AI and mission scripting so those are going to be the next big push. That and some interchangeable component based cap ship models since they will be needed if I am going to create any type of campaign that is worthy of the game title. According to my giant list of To Do’s on Trello, I am 23% done (with the list…) but included in the list are a functioning Battle Editor, ‘complex AI’ and an energy management system. So yeah, almost done!

Scanners

I’ve also been revamping the ‘radar’ system – I am calling it a scanner now in game.

The scanners will have some nice game play effects. An asteroid or debris field will make the Visual Scanner pretty tough to track enemies while it should be fine in open space. Chaff could be launched to further distort a Visual Scanner. The EM and Heat scanners can come into play in more dense areas, but stealth ships or ships trying to be stealthy might try to mask their EM or Heat by running cold or creating anomalies. A ship might jam an EM scanner with lots of waves. Of course the most lowly fighter probably won’t have the advanced scanners unless the player upgrades. The Smart scanner is the magic radar that tells you what everything is and ignores unimportant stuff.

screen_47.10722

I envision Scanner / ECM ships like the Raptors in Battlestar Galactica doing scans and blocking them. Possibly being in a wing with one would give you a scanner buff while you were close by allowing you access to scanners beyond visual that you couldn’t get alone. Additionally, some stealth ships may need to be targeted manually. Currently ship targets can be cycled through with the E key (Next Enemy Target) or C key (Closest Enemy). If a target is undetectable by scanners, you should have to get it in your crosshairs and then manually target it with the R key (Right in Front of Me Target Key). After manually targeted, the stealth ship will be added to the list of targets to cycle through… I also imagine some stealth missions where the player tries to get some surveillance by drifting undetected. Could be awesome.

targetinfo

Target Cam / Info

I’ve also added a target camera and changed the UI in that area. The stock Unity sample assets box just isn’t really meshing what I need to display there. I sort of like the angled-ness of the boxes, but they are a little limiting with what I want to display. For now I may opt for a flat UI until I build cockpits or other assets UI assets that make everything look cool. I’m more programmer than artist and my dreams for the game sort of extend beyond the art I can create for it at the moment. In the meantime, I am going to build all the cool functionality and drop the art on it when I can.

screen_155.0834

Don’t worry, it’s not really 2FPS!

Targeted Damage, Armor and Hull Damage 

You might also notice the little rectangle with a grey outline and a red inside. There is also one next to the crosshair. These are currently the armor and hull status system. Ships can now be damaged on the sides, the front and the back. If any one side’s armor goes down to zero, the hull is exposed on that side. Too much hull damage = boom! This adds some strategy to fights, you can make sure to favor one side if its damaged and keep it away from the enemy. If you lost all the armor in the front of the ship, you won’t want to play chicken with the enemy on a straight joust. Eventually some of the ship components like guns and radars will also have models stuck to the outside of the ship model. These will also be able to take damage. You can get your scanners knocked out or your engines.

 

Space Warfare: Infinite – Dev Log – Modeling ships, Base classes and Explosion Debris

I’ve been busy since the last Dev Log, but sometime its hard to tell what to update folks on. Cleaning up code is super useful for the game, but doesn’t make for screenshots. As the base ship class gets more and more cleaned up and unifies the player and AI scripts, some cool things will happen. More ship variety, AI that can use and switch between different weapon systems on their ship to match their situation, the ability to target a Friendly, press a button and hop into that ships cockpit while AI takes over yours… (yeah thats a big one…). Almost there….

I’ve been fooling around with Blender, but need to take a few online courses on UV Mapping because I am failing or at least asking ‘this has got to be easier’. I guess art assets could be a good reason for a kickstarter in the future if I can’t get the game to look right.

screen_83.59546

A semi-ok blender model of a fighter. not the best….

I did have great success in modeling debris from exploding ships. Basically just rectangular twisted scraps of metal. Thats about my skill level. But it looks cool!!

screen_86.20336

changed the zoom out for the player explosion so you can see it and take it in for a few seconds.

Space Warfare: Infinite – Dev Log: New UI Stuff and Mission Scripting

It’s hard to remember exactly what I’ve added from update to update and I hope to make more regular blog posts to keep track. Over the last week I’ve been doing more under the hood work as well as some random visual stuff to go along.

screen_20.81269

Point Defense Turrets

One major addition is point defense turrets (unique 3D model pending – for everything in the game really) that targets missiles and does a pretty ok job destroying them. The idea is that big slow moving nuke missiles fired off during capital ship battles will get knocked out of the sky — unless some ace fighter pilots can get in there and save take out those turrets! (We’ve got to justify fighter craft existence in some way right?) The code for my turret targeting had to be modified so that they could be choose to target something other than ships. This will probably come in handy one day when we want stuff to shoot bases or asteroids or cargo.

On a side note – My test model of a cap ship is a basic wall of turrets and no energy limits or management has been implemented yet, but I am sure in the future ships will not be impossible walls of laser cannons. I have some thoughts on how that would work in the future. I figure I will make ships in a component type way where you need segments to hold various things like power cores, munition bays, barracks etc. The segments will be physical chunks of the capital ship increasing the size and mass. Bigger can be heavy on fire power, but they are going to have blind spots and attack vectors that small fighters can exploit.

screen_207.0476

The turrets shooting the purple lasers are Point Defense turret. That explosion was once a slow moving nuke.

Comms! 

As you can see from the above picture, I am also working on adding some elements that will allow me to start messing around with story elements and missions.  Without comms, it’s tough to present any story or mission. The communications box will just pop in and then disappear so it’s not always interfering with view. Additionally, I am working on a Freespace 2 style ‘command’ scheme both to communicate with your fleet members and to answer back to other folks who contact you over the comm. At the moment my # keys are used for weapon equips and other usable systems, but I am going to have a comm key that enables a ‘comm’ mode for using numbered menus.

Missions! Scenarios! 

Once comms were in, I needed something to control sending comms messages. I’ll be using XML files to build missions or scenarios that will load and play out when you enter a sector or trigger something. I am thinking of them as missions and scenarios, because the story arcs will be framed more as missions, but if you are free roam and not following the main story, the game might load up various scenarios unfolding in the system you jump to so there is always something to do. So far its not too complex – we can spawn new ships and tell the player stuff.

http---makeagif.com--media-1-12-2015-prnLZoSpeaking of spawn new ships – I thought just randomly dropping ships in wasn’t cool so I gave them a warp in effect. Most fighters would probably warp in while inside a carrier, but this will do for now. I am looking forward to having a whole fleet warp in in front of a player.

UI

UI has also been worked on. The left side info box has been cleaned up a little and now works with the weapon select feature. Shows you what weapons are equipped and how much ammo they have left. Additionally the center reticul now has the energy bar, the hull hp bar and an armor bar. I also tried dropping a model of your targeted ship in the enemy info box, but I couldn’t get it to feel just right and then my game crashed. I may end up taking screenshots of the different ship models and just make sprites for them in the UI. Behind the scenes I also have a working sector map that updates positions in real time. I plan to convert it one day to something usable like another way to give orders – certainly it will be one of the ways to do that as a Captain on a cap ship.

screen_13.27957

 

Hull, Armor, Shields 

Armor was another thing I’ve added. It’s minor at the moment, but eventually it will play a big role in balance. There will be different classes of armor plate and corresponding classes of ordinance. A Class 1 projectile will lose about 25% of its expected damage against a Class 2 armor. Class 3 would reduce it to 50% and a Class 5 would basically just shrug it off with no damage. Super armored battleships might not even worry about attacks from fighters or lower class weapons. A bomber or heavy fighter with a higher armor class would have a real advantage in a dogfight against ill outfitted pirates. As for shields, I am not planning on having them on smaller ships. If you’ve been following my game dev tales, you know that I like explosions. Shield technology severely hinders the explosions:minutes ratio. Fighters and their brethren must blow up a lot. Also, I get bored when a dog fight against one enemy takes forever. Why build a high-tech spacefaring fighter jet that can’t take down its prey quickly? All fights should be quick and dangerous so shields are out for the small fries. Fly a capital ship and you can manage shields to your hearts content.

 

Space Warfare: Infinite – New Gameplay Videos with shields, new weapons, explosions!

Sadly, I die far too fast to show a lot off in these videos but if you look closely you will see the capital ship’s shields and two of its turrets blowing up any incoming missiles. I’ve also added some of the new weapon features to the UI so you can see what guns are selected and watch me flip between them. There is also ammo values now which will probably make a lone fighter long for a carrier to go back to reload on–it’s coming!

 

I’ve been working on setting up base classes for ships and weapons which is sorta why there are lots of new projectiles and guns to choose from. I also worked on making the cap ship blow up in a cool way and might use the explosion scripts for all the explosions. I sort of simulated delayed subsequent explosions. I need to make the ship come apart next instead of just disappear tho… I’ve got a list of about 48 todos still to work on before… before I make another list…

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!

Collision Avoidance using Raycasts in C# Code Snippet

screen_121.3604

I just add some pretty good code for collision avoidance in Space Warfare… Most code ideas I found around the nets about collision avoidance use the same block of Unity Javascript. Well, Javascript is taking a back seat in Unity pretty soon and I don’t really use it. I thought other folks might like the same code snippet in C#. Here it is!

 

//subtract AI thing’s position from waypoint, player, whatever it is going towards…

Vector3 target = targetYouAreFollowing.position – transform.position;

//normalize it to get direction
target = target.normalized;

//now make a new raycast hit
//and draw a line from the AI out some distance in the ‘forward direction

RaycastHit hit;

if(Physics.Raycast(transform.position, transform.forward, out hit, 800f)){

//check that its not hitting itself
//then add the normalised hit direction to your direction plus some repulsion force -in my case // 400f

if(hit.transform != transform){
Debug.DrawLine(transform.position, hit.point, Color.red);

target +=hit.normal * 400f;
}

}

//now make two more raycasts out to the left and right to make the cornering more accurate and reducing collisions more

Vector3 leftR = transform.position;
Vector3 rightR = transform.position;

leftR.x -= 2;
rightR.x +=2;

if(Physics.Raycast(leftR, transform.forward, out hit, 800f)){
if(hit.transform != transform){
Debug.DrawLine(leftR, hit.point, Color.red);
target +=hit.normal * 400f;
}

}
if(Physics.Raycast(rightR, transform.forward, out hit, 800f)){
if(hit.transform != transform){
Debug.DrawLine(rightR, hit.point, Color.red);

target +=hit.normal * 400f;
}

}

// then set the look rotation toward this new target based on the collisions

Quaternion torotation = Quaternion.LookRotation(target);

//then slerp the rotation
transform.rotation = Quaternion.Slerp(transform.rotation, torotation, Time.deltaTime * 100f);

//finally add some propulsion to move the object forward based on this rotation
//mine is a little more complicated than below but you hopefully get the idea…

transform.position += transform.forward *20f *Time.deltaTime;

 

Thanks to http://wiki.dreamsteep.com/Unity_ai and http://vimeo.com/9304844 for explaining the concept to me. If any readers are having trouble, check those sources… My numbers for distance and repulsion are based on spaceship moving at high speeds. The examples show slow moving spheres so their numbers might work better.

Next I will be adding a case where if all three raycasts hit you need to move one way or another. Otherwise, everything cancels out just about and ships still crash into stuff and explode. I kinda want that to happen a little bit so that you can feel like you are in a good asteroid chase scene, but not so much that it is over in seconds…

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.