Showing posts with label Unity. Show all posts
Showing posts with label Unity. Show all posts

Sunday, October 7, 2012

Unity RTS Grid (1.1) {

I've made some improvements to my Unity RTS Grid System. For starters, no more brick boxes and spheres! Here's a list of the significant changes since the last post.

Change Log (1.1):
  • Integrated Unity Navigation for unit pathing
  • Modified Grid System to be independent of models/shaders
  • Added fast rectangle marquee selection system (No Ray-tracing)
  • Added temporary artwork (So my eyes stop bleeding)
  • Created R-Tree system (WIP)
And here's a video demonstrating the selection system and Navigation integration:


A note on the Navigation. The building is also a NavMesh, since they will be dynamically added. Currently NavMeshes apparently can push each other around. This is a bug I am going to fix, not a strange design choice.

Selection {

The most accurate way to select an object is to trace rays from the camera's mouse position, into world-space and check for collisions with objects. For rectangular selection, the amount of rays needed increase dramatically. Since I want this system to be able to run on mobile platforms, I needed a faster method.

First thing that came to mind is unprojecting the unit's position from world-space to screen-space. Then simply checking whether the new point was within my rectangle would determine if it is selected. This only works for the single point of the unit's pivot, meaning my rectangle could intersect with most of the model without selecting it. So I simply added a radius and made it a circle. The circle is then tested for intersection with the selection rectangle and more accurate, if still approximate, selection is determined.

There are a few shortcomings with my system, however. Firstly, circles by no means accurately express all models' shapes. Also, my method [currently] doesn't take into account perspective. That is, the circles don't scale with distance from the camera. I have a solution to this but I am unsure if it is necessary or fast enough to be worth it, since my RTS camera may not create much perspective anyways. I'll just save that for another update.

}

R-Tree {

And for those interested in some technical background, here's a video demonstrating the current progress of my R-Tree spacial data structure.


This will be used to sub-group units and items into proximity based bounding rectangles (R for Rectangle). The R-Tree will allow for fast look-up of units based on position. So, for instance, when calculating precise line-of-sight, I only want to check units close to a given unit for efficiency. This allows me to quickly obtain these units.

I am not quite happy with the amount of overlap in the tree at the moment, so I will be working to minimize overlap and area of rectangle groups when I integrate it into the Grid system.

}

I'd be happy to go into more depth in any of the techniques mentioned or unmentioned, so feel free to post a question in the comments below!

-K

Tuesday, September 18, 2012

Unity Grid WIP {

Here's something recent I've been working on for a bit of fun. It's a grid system with fog of war for Unity3D. It is in its early stages at the moment, but it gives you a decent idea how some of the back-end works.

Here it is with a high cell size and a high resolution fog of war texture (for clarity of grid).


Sphere is a Unit, the big cube is a Building, and the other cubes are discoverable objects or set models that respect fog of war.

The grid is scale-able in both size (maintains cell size) and cell size (maintains size). Unity sight range and radii are based on cell sizes so they scale with cell size.

This grid will support any mesh for terrain, not just flat planes. It can also support a very high amount of cells per grid, as it is not instantiating an entire GameObject per cell. The grid lines are a simple projector, scaled to correct size, and with repeating texture.

I don't have pathing done, which will enable the unit to navigate from point A to point B by itself. So for now it just follows the mouse, at the collision point between the mouse ray and the ground.

Fog of war is computed on a per-cell basis, and upscaled to a higher resolution texture to avoid interpolation problems. In the ground shader, I simply multiply in the fog-of-war texture. In each object's shader, I check it's cell's visibility, and multiply by the appropriate tint. Simple.

I could go on and on, but I hope someone else finds this stuff interesting! I'll follow up with progress as I would like to release this for other Unity users.

-K

Tuesday, June 26, 2012

Crabs and Penguins Launches {


Finally the day has come! "Crabs and Penguins", a game I worked on this last year for Coca Cola, is finally available on the AppStore for iPad and iPhone. It will be releasing for Android, PC and Mac standalone soon. We also made a cinematic commercial of the story behind the game. Be sure to check it out at the website link below!

As lead programmer at Ember Lab, I was tasked with the game programming for the main 6 levels. This includes the player controls, player movement, collectibles and power-ups, graphics and shaders, level block-ins, and game-play testing. The primary development tools were Unity3D game engine with C# programming language. I also used some CG and ShaderLab for shader programming, as seen in my Water Shader post.

Screenshot of "Crabs and Penguins"

The game is free so if you have an iOS device, go download it and tell me what you think!

Here's the link to the Download, the Website, and the Facebook Page.

If you have any feedback, comments, or questions on how anything was done for the game, please comment below! I'd love to do a tutorial or explanation on how we made this game. Try to be specific so I can give you a detailed answer.

"Leave a crab. Return a hero."

-K

Wednesday, June 20, 2012

Water Shader {

Here's a quick demo of a mobile water shader I wrote for an Ipad game (I'll post it when it is released). I used Unity3D with ShaderLab and CG for the shader writing and C# for the scripts. I will try to package it and upload it to the Unity Asset Store soon so others can use it.


Features:


  • Efficient shader optimized for mobile devices
  • Realtime refraction of anything on opposite side of water plane
  • Sin blend between 2 normal maps for smooth normal animation
  • UV Panning normal maps
  • Reflection Cubemap
  • Renders in Opaque queue with no expensive transparency cost
  • Separate settings for fog over and under water
  • Separate settings for far clip planes over and under water (quality)
  • Controls for Transparency, RefractionFactor, ReflectionFactor, RenderTextureSize, Tiling, FogSettings, etc



Here's some more screenshots and a video: (Sorry for bad quality)










And here's the relevent vertex and surface shaders (in CG):