swift - Vehicle wheels sink in floor - Scenekit(IOS) -


i'm making car in scenekit , wheels seem sink in floor. used apples code make it. when use model works fine. but when use mine not. can't figure out why thats happening. heres picture of car wheels sinking , code right below it.enter image description here enter image description here

@ibaction func addfloor(_ sender: any) {     let floor = scnnode()     let floorgeom = scnfloor()     floorgeom.firstmaterial?.diffuse.contents = "concrete.png"      floor.geometry = floorgeom     let staticbody = scnphysicsbody.static()     floor.physicsbody = staticbody      floor.position = scnvector3(0, -10, 0)      sceneview.scene.rootnode.addchildnode(floor) }   @ibaction func addcar(_ sender: any) {     let chassisnode = getnode("rccarbody", fromdaepath: "models.scnassets/rc_car.scn")     let wheelnode0 = chassisnode         .childnode(withname: "wheelfrontl", recursively: false)     let wheelnode1 = chassisnode         .childnode(withname: "wheelfrontr1", recursively: false)     let wheelnode2 = chassisnode         .childnode(withname: "wheelrearl", recursively: false)     let wheelnode3 = chassisnode         .childnode(withname: "wheelrearr", recursively: false)       let body =  scnphysicsbody.dynamic()     body.allowsresting = false     body.mass = 80     body.restitution = 0.1     body.friction = 0.5     body.rollingfriction = 0     chassisnode.physicsbody = body     sceneview.scene.rootnode.addchildnode(chassisnode)        // add wheels     let wheel0 = scnphysicsvehiclewheel(node: wheelnode0!)     let wheel1 = scnphysicsvehiclewheel(node: wheelnode1!)     let wheel2 = scnphysicsvehiclewheel(node: wheelnode2!)     let wheel3 = scnphysicsvehiclewheel(node: wheelnode3!)     // set physics     vehicle = scnphysicsvehicle(chassisbody: chassisnode.physicsbody!,                                 wheels: [wheel1, wheel0, wheel3,wheel2 ])     chassisnode.position = scnvector3(0,-8,0)      sceneview.scene.physicsworld.addbehavior(vehicle) } 

i working on similar question, , realized adding scnfloor did not necesarily create geometry interact physicsbody.

i recommend adding sceneview.debugoptions = [.showphysicsshapes] can see bounding boxes of various physics objects interacting. in case, made floor geometry wide, long, , thin box shape rather trying use built-in "floor" geometry, created tiny cube collision interactions.

i've bit of sample code in macos playground @ github.com/heckj/scenekit-physics-playground if want view , steal useful debugging.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -