I am trying to create a SpriteKit game using Swift, which looks like a 2D gravity simulator, but when my objects get closer, they go in the opposite direction with crazy speeds.
This may be due to properties minimumRadius, categoryBitMaskor fieldBitMaskin the field and the physical application, but I don’t know for sure.
Here's the corresponding code:
override func mouseDown(theEvent: NSEvent) {
let location = theEvent.locationInNode(self)
let sprite = SKShapeNode(circleOfRadius: 5)
sprite.fillColor = SKColor(red: 0, green: 0.5, blue: 1, alpha: 1)
sprite.strokeColor = SKColor.clearColor()
sprite.position = location
sprite.physicsBody = SKPhysicsBody(circleOfRadius: 5)
let gravityField = SKFieldNode.radialGravityField()
sprite.addChild(gravityField)
self.addChild(sprite)
}
And a demonstration of the gif problem:

As you can see, the distance that objects must move in order to cause a problem seems random.
source
share