Getting direction of object moved by the physics engine

548 Views Asked by At

i am using spritekit to learn about physics behaviour in games, when a sprite node ball bounces off a surface, the physics engine will automatically calculate its new direction.

how do i get this new direction in code?

i am using swift, xcode spritekit. but object c spritekit (cocos2d) is fine too

(the aim is to get a fire trail behind the bouncing ball, but i dont know how to rotate the particle emitter based on ball's vector of movement. the emitter is currently added as a child of the ball node)

2

There are 2 best solutions below

0
On BEST ANSWER

To get the "direction" you should read the velocity property of the physicsBody of your node.

To rotate your particle emitter, you should modify the zRotation property of the node.

0
On

Well, the most best idea for getting a rotation of a node is getting eulerAngles. But since it showed radians, I converted to degrees. This is the code that I got when getting the rotation of a camera Node

print(round(GLKMathRadiansToDegrees(Float(gameController.camera.eulerAngles.z))))

Hope This helps