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.

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,

Live Streaming and Video Tutorials – Playing Strike Suit Zero on Twitch.tv

I’ve figured out how to set up a Twitch.tv account and how to do better screen cast videos on my computer. I hope to have better videos (HD) to show off future games. I also hope to start doing more How to Make Games tutorials for beginners on the web and my students. The Badger Head Games Twitch.tv channel is http://www.twitch.tv/badgerheadgames and my Youtube Channel is https://www.youtube.com/user/mikedolan03/videos. I’ll post relevant videos here, but you can subscribe to those channels as well.

As you will see from the video, while I love making games, I am not the best video game player! While I enjoy playing games, I also play stuff that I can get ideas from. The folks behind Strike Suit Zero have made a pretty impressive space battle game. I love the feeling of being in a big space battle with lots of fighters and capital ships flying around. The mission in the video also has a space station. I spend a lot of time trying to blow up a frigate and take lots of damage getting hit by its turrets. Each turret is targetable and destroyable. In my game, charging into Point Defense Turrets like that will probably make for a quick end to your ship. Taking out cap ships will require some strategic targeting of the defensive guns before making any type of bombing run.

Things I love about Strike Suit Zero:

  • Big cap ships engaging in battle
  • Nice small fish in a big fight feeling
  • Engine trails that make it easier to see enemies
  • Turrets on ships
  • Cool HUD targeting system – arrows pointing to available targets, boxes on targets, circle that tells you you are aiming right
  • nice explosions, shield effects, player hud static effects when damaged.
  • Comms w headshots  – moves story along with cinematics
  • Being able to survive but still lose a mission (sometimes the game doesn’t continue on tho, you have to play until victorious)

Anyway, look forward to my future videos. I am planning to make an intro to Unity tutorial featuring hover tanks and rockets. It should be an ‘easy’ to follow tutorial to get folks started on making their own Unity games.

Ghost Maze is Live – October’s #1GAM offering in time for Halloween!

In this game, players race through a spooky maze trying to find a portal that might grant them access to the next level. How deep will you delve into the maze? Screen Shot 2014-10-31 at 9.59.16 PM

 

In the game, you are pursued by ghosts that can kill you. You cannot hurt them, but usually you can outrun them. Each level will mean more ghosts. Don’t worry, if you die you will just respawn close to the beginning of the maze (bottom left corner). The exit is usually in the top right. The compass can help you try to navigate your way as well as the pillars and torches. There is a dungeon level, a couple different cave levels, and a temple. Once you get past the lava rock cave, levels are built of different segments so you might find a cave leading to a dungeon. There is no way to win or lose really  because the game will keep generating new mazes  forever so I’d say if you can get to level 10 that’d be a win. Also if you can do it without dieing that would be a feat. Click here to play Ghost Maze…

Controls:

WASD =Move
Mouse = Look
Shift = Run
C = Crouch
Space = Jump
M = change music volume

Technical Notes!

The mazes are generated procedurally using Conway’s Game of Life. The current default is Chance to Start at 20%, Birth 2, Death 0, Crowd 6 and Generations 6. This seemed to yield dungeons that worked best. The game tests for solvability with a flood fill algorithm and if it fails after 3 tries, it drops the player pretty close to the exit–so if that happens, congrats you get to go to the next level! The game also features an generally unseen homemade occlusion culling type thing. I disable rendering most of the maze that is not within a certain range of the player and re-enable as the player approaches. It cut the draw calls down to nothing and boosted the frame rate.

Additionally, I used the Ultimate First Person Shooter asset for my player and the spawning for the player, enemies and random objects. I used Breadcrumbs AI for the Ghosts AI. I used music from www.nosoapradio.us once again! Of course I used NGUI for my menu as always. I sure I can use it better. I need to figure out a good pause screen so players can configure the game.