This prototype is made to test one of the game mechanics in the Connect TV-Snowball fight! project. Our team wish to test the shooting mechanics we want to implement for the snowball fighting game.

First, let’s see what we want (from our game designer, Jerry):

477159016774963803

We need:

  • Some targets hiding behind some covers.
  • A slingshot or similar way to launch a snowball (which means the snowball flies in trajectory).
  • Targets stand up for 3 second, throw a snowball to you and hide back into their cover
  • The time targets stand up is the chance to attack them
  • If player is hit by certain number of snowballs, he/she loses the game.

Problems & Solutions

1.Crosshair

I started with arranging the ground in the same way as the picture:

balabala

Since Unity physics is a very handy tool to use in this case, I decided to go with that. I put a snowball in player’s hand, and when the player press space, the snowball will get more momentum, and thus fly further after the player release the button.

Here comes a problem, how do we tell the player where the snowball lands? I decided to mark the point with red so that players can know this important information.

[codeblocks name=’Crosshair_code’]

It’s just simple physics, I just need to calculate it before it actually happens. The first three lines does  the job, and the fourth line is just for keeping the mark on the ground.

ch

2. The snowball from the opponents

You may noticed the rabbits from the picture above. This comes from the Unity asset store, you can see more about that here: https://www.assetstore.unity3d.com/en/#!/content/22788

I want the rabbits to throw you some snowballs before they go back to their covers. So the snowball need to attach to their hands at the beginning, fly freely afterwards. And after hit (or miss) the player, I should secretly reset them back to the rabbits’ hands.

微信截图_20160119161512

One problem I kept encounter is that the snowballs fly in mysterious and crazy ways. I thought it was because they’re bumping with colliders of the rabbits, but it is still happening even if I disabled the rabbits’ colliders. I kept searching for solutions until I find out this:

[codeblocks name=’parent’]

So write the code in that way ends the attachment of an object from its parents. I think is is a very handy thing to use when dealing with Unity Physics, or generally, using Unity.

3. Cannot detect damage

To decide if a snowball hits the player, I put a plane near the main camera, and whenever the snowball collides with the plane, player lose a life. Looks simple and effective, but I kept seeing snowballs hit right into my face without making any damage.

I studied about the way Unity physics detect damage. Collision is calculated per frame, so for a plane that is infinitely thin, there is a good chance that the physics engine could miss it. So if there is only one plane it may not be effective. I added another plane. The miss rate decreased, but I am still not content, so I end up adding a third one.

The calculus part of my brain started  to realize some easier solutions: to achieve the best collision detection, I need infinite planes. And what is infinite number of planes?

A box. Problem solved!

Before:

微信截图_20160119171008

After:

微信截图_20160119170748