I have a vehicle in a platformer game I'm working on that I want to be able to allow rotation so it can roll up hills and such. I want to limit my vehicle to 30 degrees rotation in the negative and positive direction.
The issue is when i have rotation enabled and roll off of a cliff or straight edge drop off, my vehicle flips over off the side and lands on its head. I've been searching for a way to limit the zRotation to a set number of degrees in each direction.
I tried using the IK constraints part from this tutorial: https://www.raywenderlich.com/129895/sprite-kit-inverse-kinematics-swift-2 in my update function, but it had no effect.
Then I found this: https://developer.apple.com/documentation/spritekit/skconstraint/1519706-zrotation#declarations
that seems to be exactly what I need, but I can't quite figure out how to implement it. any advice would be appreciated!
This should do the trick: