Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(1 edit) (+1)

[Day 2] Score A Ball

Today's main goal is to implement the score and game controllers to facilitate scoring. This is all we need to have a working prototype of the game.

Approach

We have to first come up with the scoring logic of the game itself, as they differ from baseball itself. Specifically:

  • The ball must be launched from the pitchers mound towards home plate, and the player must hit the ball with the bat.
    • If the bat misses the ball on the swing, the ball is foul.
  • The batted ball must be hit beyond the outfield walls and between the two foul poles to be fair.
    • Otherwise, the ball is foul.

We can use large triggers represented by GameObjects to detect when the ball crosses the outfield walls (or out of play along the foul lines). If the ball crosses the trigger, we can judge accordingly if the ball is fair or foul. This logic is also applied to the field grounds themselves, since balls that are not home runs are fouls (it's the home run derby after all).

Above: The territory we mark as fair or foul is defined with the official baseball rules of a home run

Score

We can implement a UI text element to display the score. When the ball crosses a fair/foul trigger, it increments the score if appropriate. This is one thing I still remember from that Blizzard Unity class!

Other Changes Since Day 1

  • Stadium: I had some extra time to import a sports stadium from the Unity Asset Store. I removed the soccer field from the arena and added my baseball field in its place. The stadium does not have any colliders itself, since that is already handled in my own implementation as described above.
  • Cameras: I realized that I would want the player to observe the ball flying into the stands. Thus, after a swing, I change cameras to an outfield camera that follows the ball so that the player can judge for themselves whether the ball is a home run or not. After a judgement is made, the camera resets to the one behind home plate.

Demo

The demo for this prototype is linked here.

Controls:

  • Space Bar: Swing
  • Enter/Return: Pitch ball (once per 2 seconds)

Next

We have plenty of time left to diversify the controls of the bat-and-ball mechanics. Right now, the player can only direct the ball in certain directions via timing of the bat swing. Perhaps we can implement a power mechanic in some way, such that the player must swing hard to hit a home run? 

Anyhow, we'd need to show indicators of whether a ball is fair or foul still. We also need to define a definitive game start/end state.