I'm trying to simulate a soccer game. I have a SCNPlane
that simulates the court. I have imported a Soccer goal 3d model (.dae
file) and also a ball model (.dae
).
My ball has a dynamic physics body, the plane static and the goal is kinematic. I have set the categoryBitMask
and contactTestBitMask
for each one of the SCNNodes.
When I shoot the ball against the goal then sometimes the ball bounces and behaves as expected, but some other times the ball goes through the goal net and crosses it.
I have also assigned the SCNPhysicsContactDelegate
and the didBeginContact
is triggered when the ball bounces agains the goal but when the ball crosses it then the method is not called.
Do you know what might be happening?
Thank you!
Might be an issue with the ball moving too fast for the physics engine to calculate correctly. Try changing the "timeStep" value:
SceneKit processes the physics simulation and updates the state of all physics bodies once per the time interval specified by this property. The default value is 1/60 second (a rate of 60 Hz). A faster simulation rate provides more accuracy in simulation results—such as collisions between fast-moving objects—but at a higher cost in CPU time (which may in turn slow down your app’s rendering frame rate). Typically, you should set this property to match your target rendering frame rate (as defined by the preferredFramesPerSecond property of the SCNView object rendering your scene). https://developer.apple.com/documentation/scenekit/scnphysicsworld/1512881-timestep
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With