I am attempting to link my rigid body here, but for some reason it will not show up. I plan to change the velocity of an object when it reaches a specific speed on the x & y axes. I am attaching relevant code below along with a picture of the area:
/* THIS IS TO CORRECT THE Y AXIS BUG */
public Rigidbody rb;
private bool ballIsStuck = false;
/* Variables over */
void Start()
{
paddleToTheBall = transform.position - paddle1.transform.position;
myAudioSource = GetComponent<AudioSource>();
// rigidbody to rb
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{ // ball lock & stick
if (!hasStarted)
{
LockBallToPaddle();
LaunchOnClick();
}
}
public void FixedUpdate()
{
// Ball velocity adjustment to prevent loop
if (rb.velocity.x > -0.1 && rb.velocity.x < 0.1)
{
rb.velocity = new Vector3(0.5f, 0.5f, 0f);
ballIsStuck = true;
}
if (rb.velocity.y > -0.1 && rb.velocity.x < 0.1)
{
rb.velocity = new Vector3(0.5f, 0.5f, 0f);
ballIsStuck = true;
}
}
I found the problem, I needed to recognize it as a 2D instead of a regular rigidbody component.