1

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

Linus Juhlin
  • 1,175
  • 10
  • 31
Max Chuquimia
  • 7,494
  • 2
  • 40
  • 59

1 Answers1

0

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.

Community
  • 1
  • 1
cpimhoff
  • 675
  • 6
  • 11
  • Right, I have this working nicely already, my question is about changing the direction of the momentum rather than how to apply impulses in a forward direction – Max Chuquimia Aug 03 '16 at 22:30
  • Sorry I misunderstood. You may be able to achieve the result by rotating the body's `velocity` property to match that of the car whenever you rotate it. – cpimhoff Aug 04 '16 at 00:36
  • actually that sounds reasonable, the only thing would be making it smooth.. I guess I could check the car's rotation property every update and change it's velocity to match, though that sounds inefficient – Max Chuquimia Aug 04 '16 at 01:59