CorPruijs CorPruijs - 1 year ago 133
Swift Question

Sprite kit impulse at point

example image

I'm trying to use two points on a spaceship to create a "tank like movement" were the space ship will move forward when both points get an impulse on the

(using the
applyImpulse(CGVector, atPoint: CGPoint)
method) and turn left/right when only one point gets an impulse.

I can move the space ship forward using the
method without the
parameter and it works, but i have issues using the

When trying to use the atPoint parameter the spaceship will move really randomly, even if i apply an impulse to both jet engine 1 and jet engine 2, but i'm not sure if i apply the forces at the right point (on the jet engine spots marked on the image), the documentation is very vague about this and i don't know how to get the position of the impulses right.

Does anyone know how to get the correct positions to apply the impulses to? It should be like the ones on the image. I'm using Swift but i can read Objective C so that doesn't really matter.

I have tried the following points:

CGPoint(x: 0, y: 0) and CGPoint(x: 1, y: 0)
CGPoint(x: 0, y: 0) and CGPoint(x: spaceship.size.width, y: 0)

Answer Source

Reviewing the documentation, the points you apply the impulses at must be in scene coordinates. What that means, is you need to determine the points in the coordinates of your sprite (probably coordinates like CGPoint(x: 0, y: 1) and CGPoint(x: 0, y: -1), but you may need to play with those), then convert those to scene coordinates using convertPoint(point, fromNode: ship).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download