HomeiOS Developmentios - SKSpriteNode passing by SKShapeNode with a number of paths and...

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


I’ve a sport in Spritekit, the automotive is a SKSpriteNode, the road is SKShapeNode.

As you may see from the primary gif, once I draw an X on the high in order that the automotive falls with low velocity, it really works positive, however then drawing an X decrease (2nd gif) so the automotive has extra velocity, it can trigger the automotive to go by the traces and behave erratically.

My understanding is that is the results of not assembly the collision threshold, the automotive is touring quicker than the techniques skill 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 want 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, measurement: carSize)
    carNode.physicsBody = SKPhysicsBody(rectangleOf: carNode.measurement)
    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
   ...
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments