I'm using the SCNVehicle test as a template to add a vehicle to my game. The problem is that the vehicle bounces uncontrolably as soon as it's added to the scene:
func loadCar()->SCNNode {
let carScene = SCNScene(named: "art.scnassets/MyVan.scn");
let chassisNode = carScene?.rootNode.childNodeWithName("Toyota_Van", recursively: true)
/
chassisNode!.position = SCNVector3Make(0, 0, 0);
chassisNode!.rotation = SCNVector4Make(0, 1, 0, 0);
scene.rootNode.addChildNode(chassisNode!)
let body = SCNPhysicsBody.dynamicBody()
chassisNode!.physicsBody = body;
body.allowsResting = true;
body.affectedByGravity = true
body.mass = 80;
body.restitution = 0;
body.friction = 0.5;
body.rollingFriction = 0;
/
let wheel0Node = chassisNode?.childNodeWithName("fDWheel", recursively: true)
let wheel1Node = chassisNode?.childNodeWithName("fPWheel", recursively: true)
let wheel2Node = chassisNode?.childNodeWithName("rDWheel", recursively: true)
let wheel3Node = chassisNode?.childNodeWithName("rPWheel", recursively: true)
let wheel0 = SCNPhysicsVehicleWheel(node: wheel0Node!)
let wheel1 = SCNPhysicsVehicleWheel(node: wheel1Node!)
let wheel2 = SCNPhysicsVehicleWheel(node: wheel2Node!)
let wheel3 = SCNPhysicsVehicleWheel(node: wheel0Node!)
var min : SCNVector3 = SCNVector3Zero
var max : SCNVector3 = SCNVector3Zero
/
wheel0Node?.getBoundingBoxMin(&min, max: &max)
let wheelHalfWidth = 0.5 * (max.x - min.x)
var ve : vector_float3 = [0.0,0.0,0.0]
ve.x = wheelHalfWidth
ve.y = 0.0
ve.z = 0.0
wheel0.connectionPosition = SCNVector3FromFloat3(SCNVector3ToFloat3((wheel0Node?.convertPosition(SCNVector3Zero, toNode: chassisNode))!) + ve);
wheel1.connectionPosition = SCNVector3FromFloat3(SCNVector3ToFloat3((wheel1Node?.convertPosition(SCNVector3Zero, toNode: chassisNode))!) + ve);
wheel2.connectionPosition = SCNVector3FromFloat3(SCNVector3ToFloat3((wheel2Node?.convertPosition(SCNVector3Zero, toNode: chassisNode))!) + ve);
wheel3.connectionPosition = SCNVector3FromFloat3(SCNVector3ToFloat3((wheel3Node?.convertPosition(SCNVector3Zero, toNode: chassisNode))!) + ve);
/
let vehicle = SCNPhysicsVehicle(chassisBody: (chassisNode?.physicsBody)!, wheels: [wheel0,wheel1,wheel2,wheel3])
scene.physicsWorld.addBehavior(vehicle)
_vehicle = vehicle;
return chassisNode!