Hiya 😀!
I have some experience in SKPhysics, so it's been frustrating now as I'm struggling to make a basic car with spring suspension for the wheels. I've been able to make a vehicle where there's a "parent" point that represents the chassis and two wheel points. When these three points are connected with pin joints, SKPhysicsJointPin, the pins force the wheels to stay in place in relation to the chassis, but allow rotation around their own anchor points. So that works nicely as a car. However, I would like to add suspension to the wheels, so they have some vertical freedom of movement based on physics, as car suspension would in real life.
The problem is if I replace the pins with springs, SKPhysicsJointSpring, the springs don't stay vertical. I've tried adding sliding joints, SKPhysicsJointSliding, to them, too, to force the springs to stay in a vertical area. This seems to just make stuff go haywire. So at this point when I'm juggling three different joint types and a bunch of physicsBody, anchorPoint and axis variables, I wanted to check if someone else would know what to do. Essentially I want the same setup as in games like Hill Climb Racing.
. chassis
/ \
/ \
. . axles
| |
. . wheels
How do I implement the suspension springs?
Here's the SKPhysicsJoint reference: https://developer.apple.com/reference/spritekit/skphysicsjoint
Here's my code, with simple pin joints:
let suspensionLeft = SKPhysicsJointPin.joint(withBodyA: chassis.physicsBody!, bodyB: wheelLeft.physicsBody!, anchor: chassis.physicsBody!)
let suspensionRight = SKPhysicsJointPin.joint(withBodyA: chassis.physicsBody!, bodyB: wheelRight.physicsBody!, anchor: chassis.physicsBody!)
physicsWorld.add(suspensionLeft)
physicsWorld.add(suspensionRight)Any help really appreciated, thanks!