ios – SKSpriteNode passing by means of SKShapeNode with a number of paths and excessive velocity in Swift SpriteKit

0
31


I’ve a recreation in Spritekit, the automobile is a SKSpriteNode, the road is SKShapeNode.

As you’ll be able to see from the primary gif, once I draw an X on the prime in order that the automobile falls with low velocity, it really works high-quality, however then drawing an X decrease (2nd gif) so the automobile has extra velocity, it’ll trigger the automobile to go by means of the strains and behave erratically.

My understanding is that is the results of not assembly the collision threshold, the automobile is touring sooner than the techniques capability to catch it.

What are my choices right here, I attempted including usesPreciseCollisionDetection, however that did not assist. Neither did adjusting the velocity on the carNode nor setting the view preferredFramesPerSecond to 90.

What do I would like so as to add to get correct collision when my node is touring quick?

enter image description here

enter image description here

var carNode: SKSpriteNode!
var lineNode: SKShapeNode?


 override func didMove(to view: SKView) {
    ...
    carNode = SKSpriteNode(texture: carTexture, dimension: carSize)
    carNode.physicsBody = SKPhysicsBody(rectangleOf: carNode.dimension)
    carNode.physicsBody?.categoryBitMask = 1
    carNode.physicsBody?.collisionBitMask = 2
    carNode.physicsBody?.contactTestBitMask = 2

    carNode.physicsBody?.angularDamping = 0.5
    ...    
    addChild(carNode)
    ...
}

...

override func touchesBegan(_ touches: Set<UITouch>, with occasion: UIEvent?) {
    ...
        let newLine = SKShapeNode() 
        ...
        addChild(newLine)
        lineNode = newLine

        updateLine(to: touchLocation!)
}
...


func updateLine(to place: CGPoint) {
        let physicsBody = SKPhysicsBody(edgeChainFrom: line.path!)
        physicsBody.categoryBitMask = 2
        physicsBody.collisionBitMask = 1
        physicsBody.contactTestBitMask = 2

        line.physicsBody = physicsBody
   ...
}