Eli Deeth Blog 1


Week 2

This week i had one task that i wanted to completed and that was finish my game of pong.

Pong was a very interesting game to make as it was quite simple yet taught me a few things. To make pong i split the tasks into five groups which were paddle, ball, menu, score and Ai.

The first task i did was make the paddle and the ball.

To make the paddle move i used the code below

float speed = 3.0f;
void Update() {
var move = new Vector3(0, Input.GetAxis(“Vertical”), 0);
transform.position += move * speed * Time.deltaTime;

Next i wanted to make the ball move so i used.

rigidbody2D.AddForce (transform.right * 50);

I later changed it so that who every won the round would receive the ball this way the ball was changing from left to right.

By this point i had worked on the paddles and ball for a while and wanted to get all the ui in place so i could use it when i needed. Nothing went wrong during this part. Completing the menu was quite easy and i got it done in one go. After that i went back to my paddles and updated the directions.

By this point i was happy with my Ball, Paddle and menu so i moved onto score. Because i had everything in place i just had to remind myself how to use triggers which took about 10 minutes. It would of been shorter although i was using OnTriggerEnter instead of OnTriggerEnter2D. I made it so that when ever a point was scored the ball would be reset using

var V = Ball.rigidbody2D.velocity;
V.y = 0;
V.x = 0;
Ball.rigidbody2D.velocity = V;
ActiveCountdown = true;
Ball.gameObject.transform.position = new Vector3 (0, 0, 0);

if (ActiveCountdown == true)
countdown -= Time.deltaTime;
if (countdown < 0)
Ball.rigidbody2D.AddForce (transform.right * -50);
ActiveCountdown = false;
countdown = 1;

The last thing i had to do was make the Ai. When i first though about it i though was going to be the hardest part although in the end i found it the easiest. To make the ai i found the y of the paddle and the ball and made it so the paddle would move towards the ball.

A few goals for the future would be to add art to my pong game as i feel if i had more time i would of loved to add art.


Leave a Reply

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

WordPress.com Logo

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

Google+ photo

You are commenting using your Google+ 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