How could I create a realistic driving experience?
I use iOS Swift 3 with SpriteKit, using applyForce functions to accelerate when I press the gas button, and when braking I add friction to the physical device, I also canโt turn right, I donโt know how to do it.
Right now for a turn, I am breaking the screen using left and right turns, but I use applyForce, but it is very bad because it turns when the car stops and is very unrealistic.
When I use force only to rise, therefore, if I create a turning mechanism, and I conclude that the car will still go up.
Also note: does multitouch not work?
Any help? Thanks
override func didMove(to view: SKView) { // Multi Touch self.view?.isMultipleTouchEnabled = true car.carNode.position = CGPoint(x: 0, y: 0) car.carNode.physicsBody = SKPhysicsBody(rectangleOf: car.carNode.size) car.carNode.physicsBody?.affectedByGravity = false car.carNode.physicsBody?.angularDamping = 0.1 car.carNode.physicsBody?.linearDamping = 0.1 car.carNode.physicsBody?.friction = 0.1 car.carNode.physicsBody?.mass = 1 self.addChild(car.carNode) // HUD Display gas.gasButton.position = CGPoint(x: 300, y: -500) self.addChild(gas.gasButton) brake.brakeButton.position = CGPoint(x: 150, y: -500) self.addChild(brake.brakeButton) } override func update(_ currentTime: TimeInterval) { if touching { car.carNode.physicsBody?.applyForce(CGVector(dx: 0, dy: 180)) } } override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { for touch in touches { let location = touch.location(in: self) if location.x < self.frame.size.width / 2 { // Left side of the screen car.carNode.physicsBody?.applyForce(CGVector(dx: -100, dy: 0)) } else { // Right side of the screen car.carNode.physicsBody?.applyForce(CGVector(dx: 100, dy: 0)) } // Gas Button if (gas.gasButton.contains(location)) { touching = true } // Brake Button else if (brake.brakeButton.contains(location)) { car.carNode.physicsBody?.friction = 1 } } }

source share