Search code examples
iosunity-game-enginescenekitscene3d-model

SceneKit – Geometry penetration


I import a 3D model into the ScenekKit, then change the Euler's angle of the limb and let the limbs do the action. However, at this time, clothes and limbs will penetrate. How can I handle this situation?

enter image description here


Solution

  • I think you have to use continuousCollisionDetectionThreshold instance property. This value gives you a minimum distance the body must travel for SceneKit to apply a more precise (but more CPU/GPU costly) algorithm to detect contacts with other bodies.

    var continuousCollisionDetectionThreshold: CGFloat { get set }
    

    SceneKit's physics engine can employ two kinds of collision detection:

    • With discrete collision detection, when SceneKit simulates physics before rendering each frame (see timeStep and SCNSceneRendererDelegate), it updates the position of each physics body based on the body's velocity during that time interval, then checks to see whether the body at its new position intersects other bodies.

    • With continuous collision detection, SceneKit calculates the volume that will be traversed by a body during each frame, then checks to see whether that volume intersects other bodies. This property's value defaults to 0.0, resulting in discrete collision detection at all times. When this value is nonzero, SceneKit applies continuous collision whenever the body travels more than the specified distance within one timeStep.

    Discrete collision detection offers high performance, but can lead to inaccurate results for small, fast-moving bodies. Continuous collision detection has a performance cost and works only for spherical physics shapes, but provides more accurate results.