Hello. I’m creating a Pong game in Unity to practice my skills as a beginner game dev, and have run into an issue where the ball gravitates toward a single paddle, and once it bounces off said paddle, it will simply gravitate back to that paddle.
Here is an example to demonstrate what I mean:
How can I fix this so that it doesn’t gravitate towards any paddle at all?
You can remove the FixedUpdate. The ball doesn’t need a force constantly being added to it.
Add an OnCollisionEnter event to the bats so that when the ball collides with the bat it can be given a push with AddForce()
using UnityEngine;
public class PushIt : MonoBehaviour
{
public Vector3 pushForce;
void OnCollisionEnter(Collision collision)
{
collision.gameObject.GetComponent<Rigidbody>().AddForce(pushForce);
}
}