Search code examples
swiftvectorsprite-kitgravityskphysicsbody

Create Identical Impulse Measurements


I've notice that applying impulse can differ, depending on whether the node you are applying the impulse too is already in motion. The example of this is, if I had a node which is sitting flat on another node and you apply impulse of x: 400, the node might jump up 200 px, but if the node is in a fall like state and you apply the same impulse, the node might only jump up 50 px (I assume this is because the node is travelling in the opposite direction to the impulse direction).

My question is, is there a way of applying impulse that is in relation to its current state, so that all jumps are equal? I know 'move by X' will do this, but it doesn't really have the same effect as applying impulse.


Solution

  • Before you apply the impulse on the node, first set its current velocity to 0, and then you can apply static impulse each time.

    node.physicsBody.velocity = CGVectorMake(0, 0);