• Home  / 
  • Unity3D
  •  /  VR / VIVE Games – Day 5 – Baseball – Pitching

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.




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.


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 - 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: ????