1
votes

I have an SKPhysicsBody in my scene that I apply an impulse to whenever the user presses a button to make it move forwards. Due to it's properties, it doesn't move much with a single tap and slows down fairly rapidly, however with multiple taps it picks up speed, as expected.

I have another button for the user to tap so that the body can change it's direction. My current implementation applies an angular impulse to the body to rotate it - again, the properties of the body mean that if the user taps quickly on the rotate button multiple times then the body will take longer to stop rotating.

Currently, when the body rotates it's momentum doesn't change direction (which is what I would expect from any physics library) - in order for the user to actually make the body move in the new direction it's facing in they have to frantically press the forward button to try and slow it's previous momentum. Of course, at high speeds the body appears to skid.

How can I implement more "car-like" physics for the body? "Car-like" in that when the body rotates it's momentum updates smoothly at each interval in a new direction. Can this be done simply, or do I need to use a temporary rope, gravity field or vortex?

A diagram speaks 2000 words

1
Did you try applyForce(_:at:)?Simone Pistecchia
@SimonePistecchia It doesn't make much of a difference :(Max Chuquimia

1 Answers

0
votes

Applying a force or impulse in SpriteKit is applied in terms of the global coordinate system, not the local coordinate system of the target node.

You'll need to manually rotate the vector of force to match the node's rotation, before applying it.