Hi, I did a project inspired on Vehicle Demo. I change the scale of the car by 0.1 using Blender. After that the wheels rotated arround the car. Who can help me to fix this? Someone have an example how to resize the car? Should I use another example?
This is the code that I use:
private func setupCar(scene: SCNScene)
{
self.carScene = SCNScene(named: "Car.dae")
guard let carChassis = carScene.rootNode.childNode(withName: "chassis", recursively: true) else { return }
chassisNode = carChassis
chassisNode.physicsBody = SCNPhysicsBody(type: .dynamic, shape: nil)
chassisNode.physicsBody?.categoryBitMask = Bitmask.car.rawValue
chassisNode.physicsBody?.collisionBitMask = Bitmask.wall.rawValue
chassisNode.physicsBody?.contactTestBitMask = Bitmask.wall.rawValue
chassisNode.physicsBody?.mass = 80
chassisNode.physicsBody?.restitution = 0.1
chassisNode.physicsBody?.friction = 0.5
chassisNode.physicsBody?.rollingFriction = 0
pipeNode = carScene.rootNode.childNode(withName: "pipe", recursively: true)
reactor = SCNParticleSystem(named: "reactor", inDirectory: nil)
pipeNode.addParticleSystem(reactor)
reactorDefaultBirthRate = self.reactor.birthRate
reactor.birthRate = 0
wheel0Node = carScene.rootNode.childNode(withName: "wheelLocator_FL", recursively: true)
wheel1Node = carScene.rootNode.childNode(withName: "wheelLocator_FR", recursively: true)
wheel2Node = carScene.rootNode.childNode(withName: "wheelLocator_RL", recursively: true)
wheel3Node = carScene.rootNode.childNode(withName: "wheelLocator_RR", recursively: true)
let wheel0 : SCNPhysicsVehicleWheel = SCNPhysicsVehicleWheel(node: self.wheel0Node)
let wheel1 : SCNPhysicsVehicleWheel = SCNPhysicsVehicleWheel(node: self.wheel1Node)
let wheel2 : SCNPhysicsVehicleWheel = SCNPhysicsVehicleWheel(node: self.wheel2Node)
let wheel3 : SCNPhysicsVehicleWheel = SCNPhysicsVehicleWheel(node: self.wheel3Node)
let wheelHalfWidth = 0.5 * (self.wheel0Node.boundingBox.max.x - self.wheel0Node.boundingBox.min.x)
let wheelWidth : vector_float3 = [wheelHalfWidth, 0.0, 0.0]
wheel0.connectionPosition = SCNVector3(float3(wheel0Node.convertPosition(SCNVector3Zero, to: chassisNode)) + wheelWidth) /
wheel1.connectionPosition = SCNVector3(float3(wheel1Node.convertPosition(SCNVector3Zero, to: chassisNode)) - wheelWidth) /
wheel2.connectionPosition = SCNVector3(float3(wheel2Node.convertPosition(SCNVector3Zero, to: chassisNode)) + wheelWidth) /
wheel3.connectionPosition = SCNVector3(float3(wheel3Node.convertPosition(SCNVector3Zero, to: chassisNode)) - wheelWidth) /
let vehicle = SCNPhysicsVehicle(chassisBody: (chassisNode?.physicsBody)!, wheels: [wheel0,wheel1,wheel2,wheel3])
scene.physicsWorld.addBehavior(vehicle)
self.vehicle = vehicle
}
Thanks in advance.