Problem with Pong

Updated on July 9, 2017 in [A] 2D
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
0 on July 9, 2017

I’m following Brackeys tutorial for creating Pong. I came to Ball control part and my ball always goes to the right side. Can someone please help me? This is my code for Ball control:

#pragma strict
function Start () 
{
 var randomNumber = Random.Range(0, 2);
 var randomDirection = Random.Range(50,100);
 var randomDirection2 = Random.Range (-50,50);
 if (randomNumber <= 0.5)
 {
 GetComponent.<Rigidbody2D>().AddForce (new Vector2 (randomDirection, randomDirection2));
 }
 else
 {
 GetComponent.<Rigidbody2D>().AddForce (new Vector2 (randomDirection * -1, randomDirection2));
 }
}
function OnCollisionEnter2D (colInfo : Collision2D) {
 if (colInfo.collider.tag == "Player") {
 GetComponent.<Rigidbody2D>().velocity.y = GetComponent.<Rigidbody2D>().velocity.y/2 + colInfo.collider.GetComponent.<Rigidbody2D>().velocity.y/3;
 }
}
  • Liked by
Reply