I’m making a Breakout-like. I’m using rigidbody2d.addforce to move the ball, but it will lose all its force and start moving extremely slowly any time it hits a dynamic rigidbody2d, and in some other instances where it hits an object at an unusual angle. Is there anyway to stop this? I just want the ball to move at a single, consistent speed no matter what it hits. Ball script attached for reference.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Ball : MonoBehaviour
{
Rigidbody2D rb;
//Variable for rigidbody
bool gameActive;
//Variable for whether or not the ball is in play
public float ballForce;
//Variable for how much force is added to ball (determines speed)
void Start()
{
rb = GetComponent <Rigidbody2D>();
//Assigns ball's rigidbody to rigidbody variable
gameActive = false;
//Confirms that ball is not yet in play
}
void Update()
{
if (Input.GetButtonDown("Launch") && gameActive == false)
//If player presses launch button when ball is not active
{
transform.SetParent(null);
//Unparents ball from paddle
rb.isKinematic = false;
//Activates ball's rigidbody
rb.AddForce(transform.up * ballForce);
//Adds upward force to ball at start according to ballForce variable
gameActive = true;
//Confirms that ball is now in play, so launch function can't be activated again
}
}
private void OnCollisionEnter2D(Collision2D collision)
{
}
}