All posts in "Unity3D"

VR / VIVE Games – Day 6 – StackEm Quick [Includes Source]

HTC VIVE Game Challenge

This week, I’ve decided to start a new VIVE challenge.  Each day, I’ll be creating a new Unity game developed specifically for the HTC VIVE.

I’ll spend a single day on each game (really about 4-6h of a day), creating the base gameplay and polishing up the experience a little.htc-vive-steam-vr-logo

After each game is complete, I’ll post the results here with a gameplay video and some thoughts on how it worked out.  I’ll also provide a download link for any current Vive owners to try it out and see how the experiences turn out.

 

Game 6 is ready now!

VIVE – StackEm Quick

This time, I wanted to mix it up a bit.  If you’ve seen the other games I’ve done this week, you may have noticed they’re pretty art heavy and take full advantage of the Asset Store.  While that’s a lot of fun, and can make games look great visually (great for a 4-6h prototype), I wanted to do something this time that used NO art from the store that you can DOWNLOAD and build yourself.

In StackEm Quick, the goal is to copy the randomized stack of colors as many times as you can in 60 seconds.  Each time you match the required pattern, you’ll score and a new pattern appears.  It’s intense when the timer gets low and you have to stay calm to keep your blocks from falling over.

Source Available

Again, the source for this project is available in the download.  Just use the normal download form below and you’ll get the game and the Unity project delivered to you immediately so you can play or tweak it all you like.

Result:

 

I’m very happy with how this one ended up.  At the beginning of the day, I had no idea what I was going to build.  Well… I had a few ideas, but none of those worked out.  This one started with me not really knowing how it would end up, and resulted in something that the family was fighting over not wanting to give up.  Picking things up and generally manipulating objects in the VIVE is a lot of fun and an interaction that should be focused on heavily.

Implementation:

This project actually has more code than any of the previous.  The main gamestate is controlled by the “GameStateManager” class.  In a larger project, this logic would need to be split out across a variety of classes/state objects, but ours is small so it’s all right there.  Interactions with other objects each reside in their own classes to keep things relatively clean.

 

GameStateManager

This class is responsible for the core game loop.  It deals with the timer and tells all our other components what to do and when to do it.  There are 2 properties on this component, “Round Duration” is the length of each round in seconds.  ShapeLocation is the area to spawn our shape the player must copy (the white platform).

StackEm Quick - GameStateManager

Falling Object

Blocks

Those 4 blocks on the floor are placed in the scene.  They’re cubes scaled to 0.5 on all axis with a “MoveableObject” script attached.  The “MoveableObject” script has an Enum field defining the color.  This is used by the “ShapeComparer” to make sure you’ve stacked in the right order.

Hands

StackEm Quick - Player Hand

The hands are used to pickup blocks.  Pitching - CollidersThey’re attached to the Controllers of the [CameraRig] and have a single property for “Pickup Radius“.  This controls how far away the sphere can be from the box to pick it up.  When the player pulls the trigger, the Hands call a PickUp() method on the nearest block within the “Pickup Radius“.  When the player releases the trigger, the box is released and drops using normal Unity physics.

StackEm Quick - Camera Rig

 

 

 

Invisible Walls

To avoid players dropping their cubes off the edges (or knocking them away by trying to release 1 inside another, I’ve added some invisible walls.  These are done with cubes where the renderer is turned off.  StackEm Quick - Invisible Walls SceneThere are 6, they block stuff from falling, that’s all.hich case we don’t need to do

StackEm Quick - Invisible Walls

Shape Factory & Shape Comparer

These classes exist to create a random shape and then to compare the shape the player has built against it.  They were initially planned to create a variety of different shapes (think T, L, etc), but it turned out that building straight piles was the most fun and easiest to explain.  Building other shapes would have required the ability to stick blocks together and take them apart (which you may notice some remnants of in the code).  So for now, the random shape generation is done by taking all the available shapes, picking a random order, then spawning them in that order.

 

UI

 

The UI here has a ScoreBoard script that’s called by the GameStateManager when the ShapeComparer returns true.  It also has a timer that’s updated every frame by the “GameStateManager”.

 

Up Tomorrow: ????

 

Continue reading >
Share

VR / VIVE Games – Day 5 – Baseball – Pitching

HTC VIVE Game Challenge

This week, I’ve decided to start a new VIVE challenge.  Each day, I’ll be creating a new Unity game developed specifically for the HTC VIVE.

I’ll spend a single day on each game (really about 4-6h of a day), creating the base gameplay and polishing up the experience a little.htc-vive-steam-vr-logo

After each game is complete, I’ll post the results here with a gameplay video and some thoughts on how it worked out.  I’ll also provide a download link for any current Vive owners to try it out and see how the experiences turn out.

 

Game 5 is ready now!

VIVE – Baseball – Pitching

Today’s game is an extension of another I’ve done.  If you haven’t seen the Vive Baseball – Home Run Derby game, check it out after you read this.  Also please go check it out on Steam Greenlight and give it a vote.

Since I posted the batting game, I’d had a variety of recommendations for things to add.  One of those things was pitching.  I decided this time to see if I could add that functionality as a new game mode within my challenge time limit.

 

 

Result:

This one is fun but exhausting.  That could be just due to the fact that I have the arm of a programmer, but it’s already sore from testing.  I think it turned out pretty good though and will be a fun new mode in the Home Run Derby game.  It needs a bit of polish still, but I could definitely see it turning into a head to head game where one person pitches and the other is batting.  It could even eventually be extended to a full scale multiplayer VR baseball game if the demand exists.

It is a bit hard though in it’s current form, but like I said, it could just be my lack of physical skill.  I think in the next iteration, I’ll add some difficulty settings that help guide the ball in the right direction.

Implementation:

Some of the implementation was already done, like the HomeRun indicators and fireworks, but the majority had to be created new for this project.

 

Pitching
Pitching - Camera Rig Pitching - Colliders - SceneView Pitching - Colliders Pitching - PlayerPitcher Script Pitching - Swing Area

The Right controller has a “Hand” object attached to it.  While it doesn’t render, it does hold the ball and handle releasing & respawning of the ball.  To spawn a ball, you hold down the trigger.  Once the trigger is released, the ball is released.  This is done by having a follow component on the balls.  They follow the hand until I trigger a Release() call (when the player releases the trigger).  At that point, I also set the velocity of the ball to match the velocity of the hand.Pitching - PlayerPitcher Script

 

Falling Object

Strike / Ball Areas

Pitching - Colliders

Ball Trigger Areas with Colliders Visible


Pitching - BallTriggerAreaBefore starting this project, I already had a component called “BallTriggerArea“.  This was designed to play the HomeRun/Foul sounds in the batting game.  For this though, I needed a particle effect to play in addition to a sound, so I extended the class with a new one “BallTriggerAreaWithParticle” and attached that to 3 box colliders that you can’t see in the game.  When the ball enters one of the areas, it sets a bool on the ball saying that it’s been called (strike/ball), plays a sound, then plays a particle at the balls current position.

Pitching - Colliders

 

 

 

Swing Area

To get the granny to swing, I’ve added another invisible collider (see a pattern here?).  That collider tells her to swing the bat and sets a bool on the ball that it’s been swung at.  Later, in the Strike/Ball areas, we check that bool to make sure we don’t have her swing and play a “Ball” sound effect.  That’s why the “StrikeZoneBallTrigger” is used for on the “BallTriggerAreaWIthParticle” script.  If the goes through the swing area, all ball trigger areas tell the strike one to play instead of themselves (unless it went through strike, in which case we don’t need to do anything different).

 

AI Batter

The Granny model is available on Mixamo.com along w/ the swing animations.  For her, I added a bat made by my buddy Frank and a script that starts her swing animation by setting the “Swing” trigger on her animation controller.

 

AI Baseball Bat

The last component is the bat.  The script here listens for OnTriggerEnter, and when a ball enters, it plays a hit particle & sound, then launches the ball up and out.  No real physics are done here like they are in the batting game.  We just make her hit it hard and far in a semi-randomized direction.

 

Up Tomorrow: ????

 

Continue reading >
Share

VR / VIVE Games – Day 4 – Candy Catcher

HTC VIVE Game Challenge

This week, I’ve decided to start a new VIVE challenge.  Each day, I’ll be creating a new Unity game developed specifically for the HTC VIVE.

I’ll spend a single day on each game (really about 4-6h of a day), creating the base gameplay and polishing up the experience a little.htc-vive-steam-vr-logo

After each game is complete, I’ll post the results here with a gameplay video and some thoughts on how it worked out.  I’ll also provide a download link for any current Vive owners to try it out and see how the experiences turn out.

 

Game 4 is ready now!

VIVE – Candy Catcher

Initially, this was going to be an ice cream catching game.  The game play would have been to catch falling scoops of ice cream on a cone and stack them up.  Due to a lack of good ice cream art assets, a change had to be made.  I toyed around with a few other things, including kittens, but candy turned out to be the most enjoyable.

For this game, you have 2 plates.  Candy falls from the roof of an ice cream parlor where a miniaturized you stands to catch it and drop it onto a tray.  Each piece of candy you save earns a point.  Get as many points as you can within 90 seconds and compare with your friends and family.

 

 

 

 

Result:

This turned out to be more fun that I’d expected.  I thought catching things might be good, but didn’t realize how much balancing things adds to the game until after implementing it.  I’d started with a bucket, but it was pretty dull.  Going to plates and a tray to drop them on made it far more engaging.  My wife and kids all seemed to enjoy it and wanted to compete to catch the most candy.  Surprisingly though, my youngest had a really hard time catching them (he typically scores better than the others in most of the games).  Overall, I think it was a success and a good little game that shows a fun mechanic.

 Zombie - Spawner

Implementation:

Not much to the implementation here, but I’ll cover it anyway.  The mechanics were very simple to add.  The hardest part was finding a theme with available art that would work.

 

Candy
Falling Object

The candy spawns slightly above the ceiling.  There’s a candy spawner that picks a random area within a couple meters each direction.  The candy has a high drag value so it falls pretty slow.  When it hits the plates, that drag gets reset to 0 so it can roll right off.  Each piece also has an audioSource that contains a sound effect for when it hits the plate.

Falling Object

PlatesCamera Rig

The plates are attached to the Vive Controllers.  They have a mesh collider and a tag that says they’re plates.  The tag is used by candy to know when it should play it’s sound effect.  That’s all there is to them..

Spawners

Object Spawner

Object Spawner

You may be able to tell from the script, the spawner just has an array of Candy prefabs, a spawn time, and a randomized range.  It just runs a countdown timer and spawns a random candy from the list with the x & z position randomized from -0.3 to +0.3.

 

Up Tomorrow: ????

 

Continue reading >
Share

7 VR / VIVE Games – Day 3 – Zombie Shooter

HTC VIVE Game Challenge

This week, I’ve decided to start a new VIVE challenge.  Each day, I’ll be creating a new Unity game developed specifically for the HTC VIVE.

I’ll spend a single day on each game (really about 4-6h of a day), creating the base gameplay and polishing up the experience a little.htc-vive-steam-vr-logo

After each game is complete, I’ll post the results here with a gameplay video and some thoughts on how it worked out.  I’ll also provide a download link for any current Vive owners to try it out and see how the experiences turn out.

 

Game 3 is ready now!

VIVE – Zombie Shooter

Zombie Shooter was my 7yr old sons first choice.  When I got the Vive, his favorite game quickly became the Space Pirates.  He’s always been a big FPS fan (mainly playing TF2), and wanted me to make one too.  Where he got the Zombie idea, I’m not sure, but it seemed like a good fit and a reasonable one to put together.

In the Zombie Shooter, you have one goal…. stay alive..
The zombies keep coming, until you’re dead.  They spawn in waves every 10 seconds with a 10 second delay between each wave.  Their spawn rates are slightly randomized as are their positions, but they come from all sides.  In addition to that, some of them like to run!

 

 

 

Result:

I really liked the result here.  After a bit of iteration, my wife seemed to really get into it as well.  If you watch the video, she went for almost 6 minutes in that session alone.  The mixing of slow zombies with fast ones adds quite a bit of intensity to the game, even though only 12% of them actually run.  My kids haven’t yet had a chance to play it though, so I won’t know the full result until after this post goes live.  I’d love to hear from others though on how you like it.

Zombie - Spawner

Implementation:

This game has a few interesting implementation details that aren’t present in the previous ones.  It takes advantage of the mecanim animation system and has some basic wave spawning.

 

Guns

Zombie - GunZombie - Gun

Zombie – Gun

The guns are were a little difficult to calibrate.  For them, I’ve added a mesh from a gun pack and a “Gun” script.  The script checks for the trigger pull of a controller, and when it’s pulled does a raycast using Physics.Raycast.  The Raycast actually comes from an empty transform placed at the tip named “muzzlePoint”.  I also use this to determine where the muzzle flash should appear.
If any Zombie is in front of the gun (detected by the raycast), I call a TakeHit method on the zombie.  Other than that, they have a reload timer which is adjustable in the editor and currently set to 1 second.  If the timer isn’t refreshed, I just ignore trigger pulls.Zombie - CameraRig

They also have a laser scope, which is actually a copy of the one from the Dungeon Defense game.  This is toggled by the grip buttons and helped my wife get used to aiming.  Once she had it down though, she was able to play fine without them.

 

Zombie

The zombies took a little longer to setup due to an issue I had with animations.  For some reason, my walk animation wouldn’t properly move the zombie using RootMotion.  In the end, it turned out that just re-importing the walk animation (deleting and re-adding it) fixed the problem.  I got the Zombie and his animations from Mixamo.com.  I believe they’re free, but it’s possible I paid for them and didn’t notice.  There are also a variety of other cool zombie animations on there, but I didn’t want to go overboard on prettying this game up right now.

When they spawn, they have a 12% chance to run.  If they fall into that 12%, I just use a trigger to switch animation states from Walk to Run.  Because I’m using Unitys RootMotion, the zombie starts moving faster without any other changes.

Zombie - Animation Controller

Zombie – Animation Controller

Aside from the animations, there’s a basic call in the Update() method that just finds the player by a tag and does a transform.LookAt().  While this wouldn’t be the best way to go in a real game, because you’d want to use proper navigation, it was fine for this quick project.  If the zombie is in “attack range” of the player, he’ll make a noise from his audio source, play an attack animation, then kill the player (restart the level) if he doesn’t die within 3 seconds.

I also have the TakeHit method mentioned above in the Zombie.  This method reduces his health by 1 (initially I was going to require 2 shots, but ended up doing away with that).  When the health reaches 0 (on the first hit), I switch his animation with an animation trigger and make him schedule a GameObject.Destroy after a few seconds via a coroutine.

Spawners

This is actually the longest script of the game.  Because of that, and because there’s been some interest in code samples, here it is:

using UnityEngine;

public class Spawner : MonoBehaviour
{
    // Note I don't use the NavMeshAgent.  I was planning to but decided to ditch it for the simpler method of .LookAt
	// I do still use this _prefab though, so the zombies have a NavMeshAgent on them.  To cleanup, I should remove this
	// but I wanted to show what I initially planned vs what actually happened.
	[SerializeField]
	private NavMeshAgent _prefab;
	[SerializeField]
	private float _respawnTimerMax = 5f;
	[SerializeField]
	private float _respawnTimerMin = 2f;

	[SerializeField]
	private float _waveDuration = 20f;
	[SerializeField]
	private float _waveDelay = 10f;

	private float _countDownTimer;
	private float _waveTimer;
	private float _waveDelayTimer;
	private bool _spawning = true;

	private void Update()
	{
		_waveTimer += Time.deltaTime;
		if (_waveTimer >= _waveDuration)
		{
			PauseSpawning();
		}
		else
		{
			_countDownTimer -= Time.deltaTime;
			if (_countDownTimer <= 0)
				Spawn();
		}
	}

	
	private void PauseSpawning()
	{
		_spawning = false;
		_waveDelayTimer += Time.deltaTime;
		if (_waveDelayTimer >= _waveDelay)
		{
			_waveDelayTimer = 0f;
			_waveTimer = 0f;
			_spawning = true;
		}
	}

	private void Spawn()
	{
		var randomOffset = new Vector3(UnityEngine.Random.Range(-1, 1), 0, UnityEngine.Random.Range(-1, 1));
		var agent = Instantiate(_prefab, transform.position + randomOffset, transform.rotation) as NavMeshAgent;
		_countDownTimer = UnityEngine.Random.Range(_respawnTimerMin, _respawnTimerMax);
	}
}

I want to note that this is not to be taken as an example of a good / clean script.  It is in-fact pretty terrible and messy.  In a real game, we’d have a state system that would handle different game & spawn states.  But as a throwaway, it gets the job done fine.  Also, if you’ve used Unity much before, please take note of and start using [SerializeField].  If you don’t know what it’s for, or why you should be using it, please read my article on the subject here.

 

Up Tomorrow: Catch Something

 

Continue reading >
Share

7 VR / VIVE Games – Day 2 – Archery

HTC VIVE Game Challenge

This week, I’ve decided to start a new VIVE challenge.  Each day, I’ll be creating a new Unity game developed specifically for the HTC VIVE.

I’ll spend a single day on each game (really about 4-6h of a day), creating the base gameplay and polishing up the experience a little.htc-vive-steam-vr-logo

After each game is complete, I’ll post the results here with a gameplay video and some thoughts on how it worked out.  I’ll also provide a download link for any current Vive owners to try it out and see how the experiences turn out.

 

Game 2 is ready now!

VIVE – Archery

The goal for this game was to build a semi-realistic archery simulator.  It didn’t quite turn out that way, but it’s still an interesting experiment.

Each round, you receive 10 arrows.  Your goal is to score as many points as you can by hitting both stationary and moving targets.

 

 

 

Result:

In my head, this was a lot more fun than it turned out to be.  I’ve learned that holding something in front of your head in VR doesn’t feel great.  I think the lack of peripheral vision may be the reason for this.  While it was a neat experiment, I think in the future, I’ll avoid games that have mechanics like this.

Bow & arrow pulling also turned out to be a little more time consuming than I initially expected.  While I could get the arrow to stick to the string pretty easily, making that look right and have proper limits wasn’t feasible in such a short time.  In the end, I went with making the bow play it’s normal pull animation when you touch the string and removing the restriction of holding the arrow in place.  So while in the video it may look like it’s being pulled back and released, you can just as easily tap the string and pull the arrow controller away.  I think the lack of a proper physical feedback mechanism (like a bow built for VR) makes this interaction just not quite work.

All that said, my wife somehow still enjoyed the game.  It was one of her recommendations, so perhaps that had some influence.  Or maybe I’m just not great at judging these, I’m not sure yet.

Implementation:

There are only a few components to this game.  The more advanced ones got pulled due to not working out (bow pulling)Scene View

As a side note, I do have a Giveaway going on right now for a $25 Asset Store voucher.  If you want to win, you can enter here.

Bow

This was an asset from the Asset Store for $5.  There’s also a free one available, but in the end I wanted the animation so I paid up.

 

It works by having a trigger on a box collider attached to the string.  When the trigger is entered by the right hand controller, I reload the arrow and play the animation.Archery - Hierarchy

Arrow

The arrow was pulled off the bow asset and the pivot point had to be fixed.  For some reason, many art assets in the store have strange offsets and pivots that make no sense, this followed that trend.  Once it was fixed though, I placed a simple arrow script and an audio source on the arrow.  The script has a single public Fire method that sets its’ parent to the root (initially the parent is the bow so it will track), then it adds some force in it’s forward direction.  Because the bow’s forward was a bit messed up, I threw in a quick hack of an extra gameObject named “DirectionalTransform” that I used to get the correct forward direction (this could have been done in max/maya too, but a lot of the time these little hacks are quicker for people who haven’t used them much before).

Archery - Bow InspectorArchery - Bow Inspector

Archery – Bow Inspector

They also check for collision and if they hit the ground or a target/box I set the isKinematic property to true on it’s rigidbody so it appears to stick into the target.  You may notice in the video that there’s a bug when she hits the moving targets.  I didn’t think to make the arrows become a child of the target, so they stay floating wherever they hit it.  I considered fixing this, but thought it was more interesting to discuss the issue than resolve it.

Boxes & Targets

Moving Target

Moving Target

These just have a trigger collider and a “Target” script.  The target script just watches for trigger enter events.  When they fire, it increments the score and plays a sound.

 

 

 

 

Up Tomorrow: Zombie Shooter

 

Continue reading >
Share

7 VR / VIVE Games in 7 Days

HTC VIVE Game Challenge

This week, I’ve decided to start a new VIVE challenge.  Each day, I’ll be creating a new Unity game developed specifically for the HTC VIVE.

I’ll spend a single day on each game (really about 4-6h of a day), creating the base gameplay and polishing up the experience a little.htc-vive-steam-vr-logo

After each game is complete, I’ll post the results here with a gameplay video and some thoughts on how it worked out.  I’ll also provide a download link for any current Vive owners to try it out and see how the experiences turn out.

 

The first game in the list is ready now….

VIVE – Dungeon Defense

In this game, you play as a magic sky wizard presiding over a dungeon full of treasure.

Your goal is simple, fight off the invading goblins with your magic wands for as long as you can.

They’ll keep invading until they steal all your gold.

 

 

Result:

I really like the view in this game.  Standing over a world full of miniatures is a really interesting feeling and I think is one of my favorite ways to experience VR.
I noticed this at Oculus Connect too when they had the long CV1 demos.  One of the key demos that stood out to me was a tiny city that you could see but not interact with.

The mechanics of shooting things is pretty basic, but that helps new players get in and understand what to do quickly.

I found myself getting really low a few times to get a close up view of the little goblins I was destroying.  I think with some polish, this could be a fun little game, but I’m certain it’s lacking something key gameplay wise to make it great.

Implementation:

This game has some pretty basic systems that run it.

Goblins

The Goblins spawn from hidden spawnpoints (you could see them if you walk over to them).  Each of them is assigned a target destination that they walk toward (the chests).  When they reach the chest, they cause a Trigger event to happen that plays some sound, poofs the goblin, and reduces your remaining gold by 1.

Dungeon Defense - Spawner

Dungeon Defense – Spawner

Wands

Dungeon Defense - Camera Rig

The wands are from a pack on the asset store I grabbed for a few $.  I put a sphere on them with some random particle material that grows to full size based on the amount of time left in their refresh timers.  The refresh on them is controlled by a simple float that I tweaked in the editor until it felt right.  Each wand has a projectile prefab assigned that they spawn and launch forward using the physics system on the Rigidbody.  When they collide with anything other than the wands, they destroy themselves, spawn an impact particle, and do a quick SphereOverlap to find any Goblins within range to destroy.  Dungeon Defense - Wand Script

 

Scale

The last thing I want to explain is how to scale the world.  In this demo, the world was all built at normal scale.  Getting the miniaturized effect was as simple as scaling up the [CameraRig] 10x.  Amazingly, that worked fine with no other alterations to the game..

Baseball Home Run Derby

Also interested in a Baseball / Home Run Derby Game?
Check out my Baseball game on Steam now
<iframe src=”http://store.steampowered.com/widget/458370/” width=”646″ height=”190″ frameborder=”0″></iframe>

Up Tomorrow: Archery

 

Continue reading >
Share

Vive Baseball – Home Run Derby – On Greenlight

If you’ve visited this site before, you know that about a week and a half ago Valve sent out Vive headsets to attendees of the Vision Summit.

Since then, I’ve been hacking away to make some demos & tutorials for all of you.

In that process, I came across a prototype that appeared to be a lot of fun, so I polished it up and turned it into a real game.

It’s up on Steam Greenlight now for you to check out. (And please vote for it if you like it)

http://steamcommunity.com/sharedfiles/filedetails/?id=640736956

 

 

 

If you happen to have a Vive Pre and want to try it out now, send me an email using the Contact/Question form below.

Viveball-2

Description (Pulled from my steam page)

Vive Baseball – Home Run Derby is an exciting active baseball simulator for the Vive.
Challenge your friends and family to see who can get the most home runs before the timer runs out.
There are 3 difficulty levels, from easy (for chickens) to pro.
Do well and the crowd will cheer. Try to bunt and get booed out of the stadium!
There are a variety of bats to choose from, both wooden and aluminum.
You can play at night, during the day, or even on another planet!

It’s a lot of fun, and can be a great workout as well.
Grab it now and see how many Home Runs you can hit!

 

 

Continue reading >
Share

Vive – First Impressions & Reviews

It’s Here

If you’ve been following VR news, you know that valves Gabe Newell announced at the vision summit that they’d be giving all attendees a free Vive PRE.
Today, it arrived, and I have to say it’s pretty amazing.

image

It came in a giant box that contained many more boxes

 

image

 

image

The packaging was great and definitely kept the Vive safe.

image

Once it was all opened, you can see there is a whole lot included.

One key differentiation from the Oculus is the inclusion of hand controllers.  They’re extremely accurate, even showing the exact point on the touch pad that you’re touching.

During the tutorial, you can get a great feel of how well they’re tracked, while you inflate colored balloons and smack them around.

The Games

Some of the games/experiences were not playable with my current video card.  This isn’t the fault of the games as I’m using an AMD 280x which is at the low end for compatibility.  I plan to upgrade to the 970gtx soon and re-try those ones.  If you plan on getting a Vive, make sure to also budget for a high end video card to keep the experiences enjoyable.

Valve also included a Steam key for a set of games to try out.

This is a list of the games included free with the Vive.

I’ve included a quick description of each game and a little feedback for each.

 

8i – Gladiator / Message To the Future / The Climb / Wasteland

http://8i.com/

These unfortunately all ran too slow and choppy for anyone to enjoy.  This is probably because the video card (Radeon 280x) is a bit too slow.  It’s time to upgrade and try again next week.  It does seem like they have a streamlined video player though and could be promising.

Abbot’s Book Demo

I only tried this once, but the control scheme (warping around in the direction you’re facing) just didn’t feel right to me.  I understand what they’re trying to do, it just didn’t feel too natural in VR after so many other experiences where I walk around freely.

greenthumbupArpeture Robot Repair

Arpeture Robot Repair

Arpeture Robot Repair

[Warning: Complete spoilers] http://www.roadtovr.com/this-full-video-of-valves-aperture-science-vr-demo-is-wonderful-and-spoilerific/

This was made by Valve and quite a bit of fun.  It’s a fun/funny experience where you “attempt” to fix a robot and fail miserably.  It requires a bit of space or some awkward controls if you don’t have the space, but overall everyone who tried it thought it was enjoyable.

Cloudlands: VR Minigolf

http://futuretown.io/portfolio/cloudlands-vr-minigolf/

This game also appeared to suffer from my weak video card.  Nobody was able to even hit the ball.  It seems like a neat idea, but not until I upgrade hardware.

greenthumbupFantastic Contraption

Vive is Here - Fantastic Contraption

Fantastic Contraption


http://fantasticcontraption.com/

This was my wifes #2 game.  In it, you build contraptions in 3D as the name implies.  One of the first things she built was a car which was fun to watch.

Felt Tip Circus

http://store.steampowered.com/app/427890/?snr=1_7_7_230_150_1

This was an interesting set of mini-games where you start above a play sized circus in a room, then dive down into it and experience parts from inside.  The mini-games were pretty fun, but the interface for moving between them could be simplified / less confusing.

greenthumbupFinal Approach

Final Approach

Final Approach

http://www.phaserlock.com/#!finalapproach/c3ng

This is a VR take on the Flight Control game that was popular on mobile/steam.  It also mixed in some mini-games (putting out fires, removing seagulls) that made it interesting.  There was a bit of humor, and it was pretty forgiving on failures.  It’s definitely one of the most polished experiences available with the release.  Overall it was a hit with everyone who tried it.  The menu system however isn’t very intuitive (hold the trigger before touching buttons if you want to click them).

Jeeboman

http://futuretown.io/portfolio/jeeboman/

This is a scifi shooting game.  It’s got decent graphics and some interesting mechanics, but performance with my system was too slow to be enjoyable.  Once I’ve upgraded, I think this may be a great game.

greenthumbupJob Simulator Demo

vive is here - job simulator

Job Simulator

http://jobsimulatorgame.com/

I saw the guys who made this do a presentation at the Vision Summit.  They’ve done a great job really polishing the experience and making it fun / hilarious.  Everyone who played it wanted to do a repeat, so I’d say it was a hit.

greenthumbupNinja Trainer Vive Demo

Ninja Trainer

Ninja Trainer

https://www.youtube.com/watch?v=Fg7xjkhqpjQ

It’s fruit ninja in VR…. This so far has been the most popular and requested game played.  We’ve had competitions for high scores (110 is the current btw).  I’d rate this as the #1 game/experience included.

Sisters – Scary

http://otherworldinteractive.com/project-view/sisters/

This was a horror/jump experience.  It’s really polished and scared two teenagers out before the halfway point.  My wife is the only one who made it through the entire thing so far, and she even let out a scream & jump at the end.  Just be sure to actually look around at stuff as it seems progression is based on interaction not time.

greenthumbupSpace Pirate Trainer VR – The boys loved it

Space Pirate

Space Pirate

http://www.i-illusions.com/home/space-pirate-trainer/

You shoot at space pirates with guns.  With shields and time scale adjustment there’s enough to keep the 2 boys playing over and over.  Definitely worth a shot if you want to aim and shoot at stuff.

theBlu

http://thebluvr.com/

An underwater experience where you see beautiful imagery of sea life swimming around you.  It seems to be a relaxing passive experience with really nice art.

greenthumbupTilt Brush

Tilt Brush

Tilt Brush

http://www.tiltbrush.com/

This was a pretty amazing art experience.  It turns your controllers into a 3D paint brush and a pallet.  You can draw whatever you want in 3D.  While the creations we made weren’t anything impressive outside VR, when you see them in the headset it’s mind blowing.

 

And the Reviews

I let my family go through the experiences and gathered some feedback.
Here are their ages and favorites:

Boy #1 – 7 years old

Favorite – Space Pirates

Runner Up – Ninja Trainer

Boy #2 – 13 years old

Favorite – Space Pirates

Runner Up – Job Simulator

Girl #1 – 15 years old

Favorite – “I don’t know stop asking me”  (I think this means Final Approach)

Runner Up – “OMG I don’t know stop asking me”  (Could not translate this one)

Wife

Favorite – Ninja Trainer

Runner Up – Fantastic Contraption

Me

Favorite – Ninja Trainer

Runner Up – Tilt Brush

 

Unity Integration

This post won’t cover Unity integration with the Vive, but an upcoming one will.  If you’re interested in learning how to create your own Vive games, sign up now to be notified when the first sample is available.

 

Continue reading >
Share

Dependency Injection and Unit Testing Unity

This post will be the first in what will likely be a long series. Dependency Injection and Unit Testing are generally considered staples in modern software development. Game development for a variety of reasons is one of the few areas where this isn’t true. While it’s starting to become more popular, there are quite a few things holding back game programmers from embracing these valuable paradigms.

I’d like to open by giving a quick description of the benefits you’ll gain by embracing dependency injection.  Before you jump away thinking “I don’t need this” or “this will be too complicated”, just take a look at what you have to gain.  And let me try to quell any fears, this is something you can definitely take advantage of, it won’t be hard, it’ll save you time, and your code will be improved.

 

Benefits – What do I have to gain?

Loose Coupling

Dependency Injection by it’s nature encourages very loose coupling.  This means your objects and classes don’t have tight dependencies on other classes.  Loose coupling leads to having code that is much less rigid and brittle.

Re-usbility Across Projects

Loose coupling also makes your classes much easier to use across projects.  When your code has dependencies on many other classes or static global variables, it’s much harder to re-use that code in other projects.  Once you get into the habit of good separation and dependency injection, you’ll find that reuse becomes a near trivial task.

Encourages Coding to Interfaces

While you can certainly code to interfaces without Dependency Injection, using it will naturally encourage this behavior.  The benefits of this will become a bit more obvious in the example below, but it essentially allows you to swap behavior and systems in a clean way.

Cleaner Code

When you start injecting your dependencies, you quickly end up with less “spaghetti-code”.  It becomes much clearer what a classes job is, and how the class interacts with the rest of your project.  You’ll find that you no-longer have to worry about a minor change in one piece of code having an unexpected consequence in something that you thought would be completely unrelated.

As an example, once while working on a major AAA MMO game, I saw a bug fix to a specific class ability completely break the entire crafting system.  This exactly the kind of thing we want to avoid.

Unit Testing

This is one of the most commonly stated benefits to Dependency Injection.  While it’s a huge benefit, you can see above that it’s not the only one.  Even if you don’t plan to unit test initially (though you should),  don’t rule out dependency injection.

If you haven’t experienced a well unit tested project before, let me just say that it’s career changing.  A well tested project is less likely to slip on deadlines, ship with bugs, or fail completely.  When your project is under test, there’s no fear when you want to make a change, because you know immediately when something is broken.  You no-longer need to run through your entire game loop to verify that your changes work, and more importantly that you haven’t broken other functionality.

 

 

If it’s so good, why isn’t this common place?

Now, I’d like to cover a few of the reasons the game industry has been slow to adopt Dependency Injection & Unit Testing.

C++

While this doesn’t apply to Unity specifically, the game industry as a whole has primarily relied on C++. There were of course studios that developed in other languages, but to this date, outside of Unity, the major engines are all C++ based. C++ has not had nearly the same movement towards Dependency Injection or Unit Testing as other common enterprise languages (Java, C#, JS, Ruby, etc).  This is changing though, and with the proliferation of unit testing and dependency injection in C#, it’s the perfect time to jump in with your games.

Performance

Dependency Injection adds overhead to your game. In the past, that overhead could be too much for the hardware to handle.  Given the option between 60fps and dependency injection, 60fps is almost always the correct answer.  Now though, hardware is really fast, and 99% of games can easily support Injection without giving up any performance.

Mindset

While there are countless other “reasons” you could come across from game programmers, the key one is just an issue of mindset.  Too many people have been programming without Injection and Unit testing and just haven’t been exposed to the benefits.  They think “that’s for enterprise software”, “that’s something web developers do”, or “that doesn’t work for games”.  My goal here is to convince you that it’s worth trying.  I promise if you dig in and try dependency injection and unit testing, you’ll quickly start to see the benefits, and you’ll want to spread the word as well.

 

Dependency Injection Frameworks

When you’re searching, you may also see the DI frameworks referred to as IOC containers.

You may be wondering how you get started with Dependency Injection in Unity.  It’s not something built into the Unity engine, but there are a variety of options to choose from on GitHub and in the Asset Store.

Personally, I’ve been using Zenject, and my samples will be done using it.  But that doesn’t mean you shouldn’t look into the other options available.

Zenject

I think the description provided on the Zenject asset page does a better job describing it than I could, so here it is:

Zenject is a lightweight dependency injection framework built specifically to target Unity. It can be used to turn the code base of your Unity application into a collection of loosely-coupled parts with highly segmented responsibilities. Zenject can then glue the parts together in many different configurations to allow you to easily write, re-use, refactor and test your code in a scalable and extremely flexible way.

While I hope that after reading this series you have a good idea why you should use a dependency injection framework, and how to get started, I must highly recommend you take a look at the documentation provided on the Zenject GitHub page.

Constructor Injection

Most Dependency Injection is done via what’s called Constructor Injection.  This means that anything your class relies on outside itself is passed in via the constructor.

Example

I want to give an example of how you’d use Constructor Injection in a more general sense before diving too deep into the differences with Unity.  What I’m presenting here is a simplified version of a game state system I’m using in a Unity project currently.

In my project, I have a variety of game state classes.  The different “GameStates” handle how the game functions at different stages throughout the game cycle.  There are game states for things like generating terrain, lost/gameover, building, attacking, and in this example, ready to start.

In the game state “ready to start“, all we want to do is wait for the user to start the game.  The game state doesn’t care how the user starts the game, only that they do.  The simplest way to implement this would be to check on every update and see if the user pressed the “Fire1” button.

It may look something like this:

using UnityEngine;

public class GameStateReadyToStart : MonoBehaviour
{
    void Update()
	{
		if (Input.GetButton("Fire1"))
			SwitchToNextGameState();
	}

	private void SwitchToNextGameState()
	{
		// Logic to go to next gamestate here
	}
}

This will work, it’s simple, and quick to implement, but there are some issues with it.

 

Problems

  • Our gamestate is a monobehaviour so we can read the input during the update.
  • The Input logic is inside a class who’s job isn’t Input.  The gamestate should handle game state/flow, not input.
  • Changing our input logic requires us to touch the gamestate class.
  • We’ll have to add input logic to every other gamestate.
  • Input can’t be easily varied across different devices.  If we want a touch button on iPad and the A button on an xbox, we have to make bigger changes to our gamestate class.
  • We can’t write unit tests against our gamestate because we can’t trigger input button presses.

You may be thinking that’s a long list, but I guarantee there are more problems than just those.

Why not just use a Singleton?

The first answer you may come across to some of these problems is the Singleton pattern.
While it’s very popular, simple, and resolves half of our issues, it doesn’t fix the rest.
Because of that, outside the game development world, the singleton pattern is generally considered bad practice and is often referred to as an anti-pattern.

 

Let’s try some separation

Now, let me show you an easy way to resolve all of the problems above.

public class GameStateReadyToStart
{
    public GameStateReadyToStart(IHandleInput inputHandler)
	{
		inputHandler.OnContinue += () =>
		{
			SwitchToNextGameState();
		};
	}

	private void SwitchToNextGameState()
	{
		// Logic to go to next gamestate here
	}
}

Here, you can see we’ve moved input handling out of the “gamestate” object into it’s own “inputHandler” class.  Instead of reading input in an update loop, we simply wait for the InputHandler to tell us when the user is ready to continue.  The gamestate doesn’t care how the user tells us to continue.  All the gamestate cares about is that the user told it to switch to the next state.  It’s now properly separated and doing only what it should do, nothing more.

The “IHandleInput” interface for this example is very simple:

using System;

public interface IHandleInput
{
    Action OnContinue { get; set; }
}

Now, if we want to switch input types across devices, we simply write different implementations of the “IHandleInput interface.
We could for example have implementations like:

  • TouchInputHandler – Continues when the user presses anything bound to “Fire1
  • GUIBasedInputHandler – Continues when the user clicks a GUI button
  • VoiceInputHandler – Continues when the user says a phrase
  • NetworkInputHandler – Continues when the user presses something on another device (think controlling a PC game with a phone)
  • TestInputHandler – Continues via a unit test designed to verify state switching doesn’t break

 

Time to Inject!

Now without going too much deeper into my example, you may be thinking “that’s nice, but now I have to pass in an input handler and manage that”.

This is where dependency injection comes into play.  Instead of creating your handler and passing it into the constructor, what we’ll do is Register the handler(s) we want with our Dependency Injection Container.

To do that, we need to create a new class that derives from the Zenject class “MonoInstaller

using System;
using UnityEngine;
using Zenject;
using Zenject.Commands;

public class TouchGameInstaller : MonoInstaller
{
    public override void InstallBindings()
	{
		Container.Bind<IHandleInput>().ToTransient<TouchInputHandler>();
		Container.Bind<GameStateReadyToStart>().ToTransient<GameStateReadyToStart>();

		Container.Resolve<GameStateReadyToStart>();
	}
}

In the TouchGameInstaller class, we override InstallBindings and register our 2 classes.

Line 13 simply asks the container for an instance of the game state.

This is a very simplified version of the Installer with a single game state, later parts of this series will show how we handle multiple game states.

What we’ve done here though is avoid having to manage the life and dependencies of our “gamestate” class.
The Dependency Injection Container will inspect our classes and realize that the “GameStateReadyToStart” class has a dependency on an “IHandleInput“, because the constructor has it as a parameter.
It will then look at it’s bindings and find that “IHandleInput” is bound to “TouchInputHandler“, so it will instantiate a “TouchInputHandler” and pass it into our “gamestateautomatically.

Now, if we want to switch our implementations on different devices, we simply switch our our “TouchGameInstaller” with a new installer for the device and make no changes to our GameState classes or any existing InputHandler classes.  We no longer risk breaking anything existing when we want to add a new platform.  And we can now hook up our GameState to unit tests by using an Installer that registers a TestInputHandler.

 

You may realize that I haven’t injected any gameobjects yet, and could be wondering how this works with monobehaviors that can’t constructors.

In the next part of this series, I’ll explain how to hook up your gameobjects and monobehaviors with the dependency injection framework and continue the example showing how the entire thing interacts.

 

 

Continue reading >
Share
Page 19 of 21