Currently creating a VR table tennis game for Quest, but I’m struggling a bit with a few issues, mostly at the moment ensuring that the rigidbody paddle follows the player’s hand and the collision response of the ball hitting the paddle. Any help or suggestions would be appreciated! Here’s my current approach, :
- Running on Quest so I set the fixed timestep to 1/72
- The ball is a rigidbody (continuous dynamic collision detection, movement is set to interpolate), and I’m manually controlling the movement of the ball by setting the rigidbody’s velocity (rb.velocity = ballVelocity), applying gravity manually each frame (ballVelocity.y -= grav * Time.deltaTime). That bit seems to work well.
- When ball collides with paddle (OnCollisionEnter()), ball will reflect off of the paddle with Vector3.reflect(ballVelocity.normalized,hitFaceNormal) using the ball’s direction (normalized velocity) as the input and the paddle’s normal for the face that was hit.
- We then set the magnitude of the reflection vector based on the ball’s speed, added to the paddle’s movement vector (using Vector3.Dot to see how much of the paddle’s current velocity is aligned with the direction the ball was reflected)
There’s a bit more to it than that, but that’s the basic idea for now, and it works mostly well. But I’m struggling with a couple of issues.
First major issue… the paddle needs to follow the player’s hand INSTANTLY in VR every frame. The paddle must be able to detect collisions with the rigidbody ball, so the paddle needs to also be a rigidbody. But, I’m not sure of any way to make the rigidbody paddle follow without lag.
- Making a separate paddle rigidbody collider object that follows around the paddle by setting, in FixedUpdate(), the rb.velocity = (paddle.transform.position - rb.position) * 100 can lead to lag or the rigidbody overshooting the position and settling in over the course of a couple frames.
- Making a separate paddle rigidbody collider object and using a physics fixed joint to connect it to a child transform of the real non-rigidbody paddle works, but also introduces lag, where the rigidbody lags behind the actual position of the paddle.
What happens is that, when I hit the ball, the rigidbody collider that follows behind my paddle can be so offset sometimes, still catching up, that you can instantly notice that the ball didn’t visually collide with your paddle, or goes right through your paddle for a couple frames or so, it feels loose and sloppy, and I’m pulling my hair out coming up with a solution. I considered a custom raycasting approach where the ball will spherecast, and the paddle can boxcast, and doing away with this whole physics and fixed timestep but… since you can rotate and swing your paddle that way too, I’m struggling with boxcasting for rotations rather than just positions (eg. paddle is facing this direction, then wants to rotate to a new direction without physically moving, then you can boxcast but which orientation? the current orientation, or the desired orientation that it’s rotating to? etc.).
Any help, direction, resources, etc. would be amazing, thanks!!