Battle pong #3 – Moving to the core

Last week the game was in the following state :

  • the Y axis movement is working, there is no X axis movement
  • I need to rewrite the script to have a correct number of coins
  • I need to write the core behavior.

So… Let’s do it !

The X movement

The InputManager already had many defaults values

The X axis was already defined in the Unity Input Manager so all I have to do is linking it with the script on the RigidBody2D the exact same way you move the Y axis.

So by modifying the Update method of the tutorial, I just add the necessary code to take the X axis into account :

horizontalAxis = Input.GetAxis ("Horizontal");
//Go front
if (horizontalAxis > 0) {
vel.x = speed;
//Go back
else if (horizontalAxis < 0) {
vel.x = -speed;
else {
vel.x = 0;

Hmmm I realize I maybe need to add some way to display code on this website…. Anyway for now I control player with the keyboard since I try to setup all the mechanisms of cores first. It is a little bit fast but it will do for now.

Getting a correct number of cores

Nothing tricky here but still have to take care of that. There are two things to take into account here : first the background size and second the camera size.

The native approach would be to take the background size but… Depending on the camera size maybe the position of your objects will be off screen, so the best idea is to take the camera height and compute the size and position of the cores from this. Results is clearly less messy than the first one. Each core will be linked to a wall (left or right) and we will use this link to know which player destroyed the core.

Setting up the cores behavior

Once again nothing tricky here, I just realized that I had to modify the ScoreWall class from the tutorial by just adding a Destroy() call in the method. By doing so, of course the script will switch from the wall to the cores directly…

Second step will be to modify the collision to trigger. I do this in anticipation to the arrival of bonuses that will NOT be trigger type. So let’s avoid messing up with different items collisions. It gives the following result :

void OnTriggerEnter2D(Collider2D hitInfo){
if ( == "Ball") {
string wallName =;
GameManager.Hit (wallName);
Destroy (gameObject);

Player 1 viciously attack Player 2 after loosing 3 cores ! (Player 2 is still human controlled here)

Bonus before Chinese New Year !

Let’s be honest, it’s starting to take shape BUT it’s not really good looking for now. So in order to keep working on a sexy game, I started looking for graphic assets to make the game more readable.

Less colors, more blue, more zen

And that’s it for today ! I’ll be on trip for Chinese New Year. On next articles I will add more gif or screencaps in order to show moving things !


Have a nice Chinese New Year celebration !

Battle pong #3 – Moving to the core

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s