Table tennis racket physics problem/find solution.

Hello unity developers. I’m trying to create simple ping-pong (table) game and have a big issues with a physics of the objects. For first the physic of ball. I try to use standards unity methods but bouncing of the ball was to bad and i decide to use script method, something like this:

private void OnCollisionEnter(Collision collision)
    {
        var speed = lastFrameVelocity.magnitude;
        var direction = Vector3.Reflect(lastFrameVelocity.normalized, collision.contacts[0].normal);
        GetComponent<Rigidbody>().velocity = direction * Mathf.Max(speed, minVelocity);
    }

and ball physics is now look great but then if find that when i try to hit it with the racket on small speed not all but seem to be good (i think just edit the script to check racket velocity to add to speed of the ball) but on a high speed ball just path through the racket and changing collision detection to continues and else not give any result. I think i must check the racket position and ball hit with the script (maybe using ray-cast) and then change the force and ball trajectory. Am i right? maybe someone have a good solution for this.

Hello, and welcome to Unity forums!

You should configure the collision mode to Continuous Dynamic in both the rackets and the ball:

According to the doc this collision mode only works with primitive colliders (sphere, capsule, box). However, I’m not sure if this has changed recently, so I’d also try with convex mesh colliders.

I use this parameters but get something like this

and on racket i have simple box collider for now and on the ball standard sphere collider.

The racket must be a kinematic rigidbody, and you must move it by calling Rigidbody.MovePosition and Rigidbody.MoveRotation from FixedUpdate. I assume that the ball is already a regular non-kinematic rigidbody.

1 Like

Yep, my problem was that i use simple update in Racket position changing when i need FixedUpdate. This solve the problem, i just forget to change when create this script update to fixed. Thanks!!

1 Like