CorPruijs - 23 days ago 6x

Swift Question

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

`physicsBody`

`applyImpulse(CGVector, atPoint: CGPoint)`

I can move the space ship forward using the

`applyImpulse(CGVector)`

`atPoint`

`atPoint`

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.

EDIT:

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

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)`

.

Source (Stackoverflow)

Comments