Collision of surfaces created by the AR Plane Manager

I am creating a scene of spheres with rigidbodys that need to bounce off surfaces created by the AR manager. this sometimes works, however the objects occasionally get stuck and glide along the surfaces.

I created a manager script in my scenes that handles the balls collision:

private void HandleARSurfaceCollision(CollisionHandler handler, Collision collision)
    {
        Debug.Log($"Ball {handler.gameObject.name} collided with an AR surface!");
        Movement movement = handler.GetComponent<Movement>();
        movement?.ApplyReflection(collision);
    }

And then in the Movement script attached to each ball I have this function:

public void ApplyReflection(Collision collision)
    {
        if (rb == null) return;

        // Reflect the velocity based on the collision normal
        Vector3 collisionNormal = collision.contacts[0].normal;
        Vector3 direction = Vector3.Reflect(rb.velocity.normalized, collisionNormal);

        // Maintain the speed or apply force
        float speed = rb.velocity.magnitude;
        rb.velocity = direction * Mathf.Max(speed, 2f);

        Debug.Log($"Bounced! New velocity: {rb.velocity}");
    }

The balls rigidbody has these properties:

It also has a physics material applied with these properties:

This works about 80% of the time, but sometimes the balls fail to bounce off the surfaces, instead gliding along them.

Hey there, I suggest adding the tags Physics and AR-Foundation tags to your post to get more eyes on this. It might also help to share the exact properties you’ve set for the physics material and rigidbody. Cheers and good luck!

1 Like

This is more of a physics problem than an AR Foundation problem. I assume your ARPlane prefab has a collider on it for the physics to detect the collision. Since you are manually setting the velocity in code instead of letting the physics system calculate it I think you want to enable your rigid body’s IsKinematic flag. Otherwise the physics rigid body will be fighting with your code for the objects actual velocity.

Or let the physics system handle everything and don’t manually calculate and set the velocity yourself. If you remove your code, do you still have the problem?

ive removed all of the movement code logic other than an initial force I apply the balls on start, to get them to move in random directions.

    public Rigidbody ball;
    public Vector3 velocity;

    void Start()
    {
        // Add force once at start

        float randomForce = Random.Range(0.5f, 3);
        Vector3 randomDirection = Random.insideUnitSphere.normalized;

        ball.AddForce(randomDirection * randomForce, ForceMode.VelocityChange);
    }

When the balls reach a surface, they seem to get stuck and glide along them - I need them to bounce off surfaces without applying any gravity, similar to this diagram:

Is it possible to configure this sort of logic entirely through the balls rigidbody?

I’ve removed the AR Foundation tag from this post, as you are asking a purely Physics question at this point. You mention that your ball has a Physic Material; did you put the same material on the planes? I don’t know if that would work but that’s my guess. Hopefully Physics team can chime in.