Spritekit Skphysicsjointfixed Odd Behaviour

SKPhysicsJointFixed doesn't keep nodes together while moving one

This is very strange indeed, but I have encountered similar things before.
Its the AllowRotation on the physicsBody that creates the problem.

fix:

node.physicsBody?.allowsRotation = true

Note:
your physics body for the second node is a bit off. I suggest you do like this instead:

node.physicsBody = SKPhysicsBody(rectangleOf: node.size)

And your joint is currently in the right corner of the nodes, Fix:

let anchor = CGPoint(x: 0, y: -node1.size.height/2)

unless you want it to be like that ofc :)

One last tip if you don't already know it. set showPhysics in your gameViewController to see an outline of your physics bodies. it does help a lot when working with physics.

view.showsPhysics = true

Using a fixed SKPhysicsJoint to attach a platform detection hitbox as a child to a player sprite changes player's collision and detection bit masks

I found the solution.

It seems there's some bugs with fixed joints and the answer was to use a "pin" joint instead. This StackO question goes into detail about a rotation bug with fixed joints. On a whim I decided to change my fixed joint to a pin and now the child behaves as you would expect, positionally speaking anyway.

So it appears fixed joints have a few bugs that need to be worked out.

SpriteKit how to add a fixedJoint?

You put the fixedJoint into an array, try this instead, omitting [ and ].

let anchor = CGPointMake(hero.position.x + 10,hero.position.y)
let fixedJoint = SKPhysicsJointFixed.jointWithBodyA(hero.physicsBody!, bodyB: shield.physicsBody!, anchor: anchor)

Note: If you are not mutating your properties make them let instead of var.



Related Topics



Leave a reply



Submit