pmndrs / react-three-rapier

🤺 Rapier physics in React
https://react-three-rapier.pmnd.rs
MIT License
1.02k stars 57 forks source link

Ball Collider Fails to Interact with HeightfieldCollider in React Three Rapier #564

Open itdat opened 9 months ago

itdat commented 9 months ago

I am encountering an issue in React Three Rapier where a BallCollider passes through a HeightfieldCollider without any collision detection. This issue does not occur when the HeightfieldCollider is replaced with a CuboidCollider, where the BallCollider correctly collides and stops.

The setup consists of two RigidBodies, one with a BallCollider and the other with a HeightfieldCollider. The BallCollider is set with a dynamic type and positioned above the HeightfieldCollider.

Here's a snippet of the relevant code:

<Physics debug>
      <RigidBody type="dynamic" position-y={100}>
            <BallCollider args={[5, 5]} />
      </RigidBody>
      <RigidBody type="fixed">
             {/* <CuboidCollider args={[100, 1, 100]} /> */}
            <HeightfieldCollider args={[3, 3, [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2], { x: 80, y: 1, z: -80 }]} />
      </RigidBody>
</Physics>

The expectation is for the ball to collide and interact with the heightfield surface. However, in practice, the ball passes through the heightfield collider as if it's not there.

This behavior is observed consistently and can be replicated using the above code. Interestingly, when the HeightfieldCollider is replaced with a CuboidCollider, the ball behaves as expected and stops upon collision.

Here is a screenshot illustrating the issue:

image

I am looking for insights into why this might be happening and how to resolve it. Is there a specific configuration that I am missing, or could this be a potential bug in the library? Any help or guidance would be greatly appreciated.

Thank you!

wtong2017 commented 1 month ago

You might need to set the active collision types to include KINEMATIC_FIXED.

E.g.,

<BallCollider args={[5, 5]}  activeCollisionTypes={ActiveCollisionTypes.DEFAULT | ActiveCollisionTypes.KINEMATIC_FIXED} />

According to the documentation, collision detection between fixed and dynamic is disabled by default (https://rapier.rs/docs/user_guides/javascript/colliders#active-collision-types).