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
Implementing Swift Protocol Methods in a Base Class
Type Check Operator (Is) for Check VS Homogenous Protocol: Why Can This Be Done for Optionals
Why Is Deinit Not Called Until Uiview Is Added to Parent Again
Swiftui Button Interact with Map
How to Set an Initial Value for @Nsmanaged Property Pfobject Subclass
Are Swift Constants Lazy by Default
Swiftui Editbutton Action on Done
Rotating Uitextview Programmatically
Notification Extension Access Core Data
How to Set Avaudioengine Input and Output Devices (Swift/Macos)
Protocol Can Only Be Used as a Generic Constraint
Swift: Generics and Type Constraints, Strange Behavior
What Is Darwinboolean Type in Swift
Swift Any Difference Between Closures and First-Class Functions
Textfield Delegate Shouldchangecharactersinrange