Skip to content

Instantly share code, notes, and snippets.

@denforlatte
Last active May 17, 2017 13:22
Show Gist options
  • Save denforlatte/1e81566125b094fb01a9de4e579d6380 to your computer and use it in GitHub Desktop.
Save denforlatte/1e81566125b094fb01a9de4e579d6380 to your computer and use it in GitHub Desktop.
void OnCollisionEnter2D (Collision2D collision) {
Vector2 xtweak = new Vector2 (Random.Range (-ballKick,ballKick),0f);
Vector2 ytweak = new Vector2 (0f,Random.Range (2f,ballKick));
if (hasStarted) {
if(GetComponent<Rigidbody2D>().velocity.x >= -bounceTolerance && GetComponent<Rigidbody2D>().velocity.x <= bounceTolerance){
print ("Engage X kick!");
GetComponent<Rigidbody2D>().velocity += xtweak;
} else if (GetComponent<Rigidbody2D>().velocity.y >= 0 && GetComponent<Rigidbody2D>().velocity.y <= bounceTolerance){
print ("Engage Y kick!");
GetComponent<Rigidbody2D>().velocity += ytweak;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment