Hello
I try to understand the movement of a character with physics. To do this, I imported max into the fox2 file provided by Apple. I apply a .static physics to it and I have a floor with static physics and static blocks to test collisions everything works very well except that Max is above the ground.
He doesn't touch my ground. I couldn't understand why until I had the physicsShapes displayed in the debug options. With that I see that if max does not touch the ground it is because the automatic shape is below Max and this shape touches the ground.
So I would like to know why the shape is shifted downwards and how to correct this problem?
I did tests and the problem seems to come from physicsBody?.mass. If I remove the mass, the shape is correct but when I move my character it crosses the walls and when I put it on it is well stopped by the static boxes...
Someone with an idea of how to correct this problem?
This is my simplify code
import SceneKit
import PlaygroundSupport
// create a scene view with an empty scene
var sceneView = SCNView(frame: CGRect(x: 0, y: 0, width: 300, height: 300))
var scene = SCNScene()
sceneView.scene = scene
// start a live preview of that view
PlaygroundPage.current.liveView = sceneView
// default lighting
sceneView.autoenablesDefaultLighting = true
sceneView.allowsCameraControl = true
sceneView.debugOptions = [.showPhysicsShapes]
// a camera
var cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
cameraNode.position = SCNVector3(x: 0, y: 0, z: 3)
scene.rootNode.addChildNode(cameraNode)
// Make floor node
let floorNode = SCNNode()
let floor = SCNFloor()
floor.reflectivity = 0.25
floorNode.geometry = floor
floorNode.physicsBody = SCNPhysicsBody(type: .static, shape: nil)
scene.rootNode.addChildNode(floorNode)
//add character
guard let fichier = SCNScene(named: "max.scn") else { fatalError("failed to load Max.scn") }
guard let character = fichier.rootNode.childNode(withName: "Max_rootNode", recursively: true) else { fatalError("Failed to find Max_rootNode") }
scene.rootNode.addChildNode(character)
character.position = SCNVector3(0, 0, 0)
character.physicsBody = SCNPhysicsBody(type: .static, shape: nil)
character.physicsBody?.mass = 5
Thank you!