Im making a 2d pong like game with powerups. one of the powerups doubles the velocity of the ball. Ive been having problems with the physics engine as when I hit the ball with the side of my paddle the ball speeds up alot. Is there any way to lock the velocity to a certain number unless the powerup is activated?`public Rigidbody2D rb;
public float ballForce;
public Rigidbody2D powerUpRB;
private bool timerStart = false;
private float timeLeft = 1f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyUp(KeyCode.Space))
{
rb.velocity = new Vector2(ballForce, ballForce);
}
}
void OnCollisionEnter2D(Collision2D coll)
{
if (coll.gameObject.name != "doubleBallSpeed") return;
rb.velocity = new Vector2(ballForce * 2, ballForce * 2);
StartCoroutine("DelayTime");
Destroy(coll.gameObject);
}
IEnumerator DelayTime()
{
yield return new WaitForSeconds(5f);
rb.velocity = new Vector2(ballForce / -2, ballForce / 2);
}
}