3

So. I'm attempting to create an SCNPhysicsVehicle in SceneKit. The problem I am getting is that the vehicle chassis does collide with the floor in my scene, although the wheels don't. The wheels just go straight through the floor until the chassis collides with the floor. I was wondering whether there was some thing I am forgetting? I have never seen anyone else set a collision category or category bit mask for the wheels on an SCNPhysicsVehicle. With that being said, I did even try that but no luck!

Very big thanks in advance.

    let carScene = SCNScene(named: "art.scnassets/Textures/rc_car.dae") //rc_car.dae
    let chassisNode = carScene!.rootNode.childNode(withName: "rccarBody", recursively: true)!
    chassisNode.position = SCNVector3Make(0, 10, -30)

    let body = SCNPhysicsBody.dynamic()
    body.allowsResting = false
    body.mass = 80
    body.restitution = 0.1
    body.friction = 0.5
    body.rollingFriction = 0
    chassisNode.physicsBody = body
    scene.rootNode.addChildNode(chassisNode)


    let wheelnode0 = chassisNode
        .childNode(withName: "wheelLocator_FL", recursively: true)!
    let wheelnode1 = chassisNode
        .childNode(withName: "wheelLocator_FR", recursively: true)!
    let wheelnode2 = chassisNode
        .childNode(withName: "wheelLocator_RL", recursively: true)!
    let wheelnode3 = chassisNode
        .childNode(withName: "wheelLocator_RR", recursively: true)!


    let wheel0 = SCNPhysicsVehicleWheel(node: wheelnode0)
    let wheel1 = SCNPhysicsVehicleWheel(node: wheelnode1)
    let wheel2 = SCNPhysicsVehicleWheel(node: wheelnode2)
    let wheel3 = SCNPhysicsVehicleWheel(node: wheelnode3)

    vehicle = SCNPhysicsVehicle(chassisBody: chassisNode.physicsBody!,
                                wheels: [wheel0, wheel1, wheel2, wheel3])



    chassisNode.physicsBody?.collisionBitMask = USBitMaskManager.boundary | USBitMaskManager.sphere
    chassisNode.physicsBody?.categoryBitMask = USBitMaskManager.sphere

//        scene.physicsWorld.addBehavior(vehicle)

    return vehicle

2 Answers2

0

did you check github? There are several projects out there regarding Apples Vehicle Demo... e.g. one is here: https://github.com/ooper-shlab/SceneKitVehicle1.0-Swift

Chris
  • 7,579
  • 3
  • 18
  • 38
0

The .dae model, from which you load your chassis, needs to have the 4 wheels as child nodes.

Otherwise it doesn't work.

It’s also worth noting that you can’t scale wheels. Wheels default to using the node scaled at 1.0.

So the .dae model must be the correct size when scaled to 1.0.

enter image description here

Michael N
  • 436
  • 5
  • 6