Getting direction of object moved by the physics engine - objective-c

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)

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.

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

Related

Sprite Kit Physics Simulation - bodies never come to rest

With Sprite Kit physics I have a simple setup with a ball bouncing inside a rectangular edge shape.
It all works fine, however the ball never comes to rest. The resting property is always NO and I can see that the ball animation keeps making a little bit of movement when it should be resting.
Sprite Kit is based on Box2D and here there is a doSleep option on the physics world, but I cannot find something similar with Sprite Kit.
What am I missing?
You should use restitution. A property for setting the bounciness of the physics body in sprite kit. Actually, it is a property describing how much energy a body retains when it bounces off of another body. Dot operator can be used with the ball's sprite name to access the restitution property.

How to clip part of a sprite based on its position?

I'm designing a game in Cocos2d, and at one point I have coins shooting out on a platform from a zelda-ish perspective. I'd like to display the coin's shadow sprite (a different sprite from the coin) on the platform, but mask or clip the shadow sprite on the edge of the platform. The coin can continue off the edge of the platform, but the shadow should stop at the edge. The platform also moves, so I need the shadow sprite to track with the platform's movement.
I thought it could work to use a CCClippingNode for this, but I can't add it as a child of anything in a spriteBatchNode which is how I'm making my platform. Without having the shadow as a child of the platform, I'll mess up z-order and the shadow movement won't track correctly. I also checked out Ray Wenderlich's tutorial on masking a sprite but I don't think that'll work since it looks like it masks an individual sprite texture and not an area of the view where the sprite shouldn't be displayed. Any ideas on how to solve this?

Cocos2d - Move sprite in curved path

I am creating a Catapult game in Cocos2d in which the catapult is at the bottom center of the screen and we throw stones on the objects falling from the top of the screen. I tried using Bezier curves for this purpose but problem is that I am not able to calculate control points for drawing bezier curve. I need to move sprite of the stone on a curved path when released from the catapult.
Can anyone please guide me how can I achieve it?
Thanks and Best Regards
why you don't use physics for that?
use box2D is integrate with cocos2D, config the world, gravity, and physics budies,so.. the effect of catapult is automatic when you shot a bullet.

Three.js: Camera Collision on Terrain

How should I go about adding camera collision to a terrain in three.js.
The terrain is from 'mrdoob's three.js' examples and is randomly generated and I am currently converting it to height map.
I am thinking of implementing the collision as follows:
Create a 'box' object around the camera
If the box object is not touching the terrain, move the camera down.
If the box object IS touching the terrain, keep the Y axis of the camera.
How should I go about doing this?
The theory is that you send a ray from the location you are (camera position) straight down. You find the intersection point and based on the distance you decide what to do. Implementation wise I cannot help you but THREE.Ray should help you.

binding camera to my game person with acceleration, deceleration, ect in libgdx project

So, how can I do this?
For example, my person goes right and camera starting to move to persons coordinates with acceleration, when he stoppes - camera moves to persons coordinates with deceleration. Of cource, I can make it by myself, but is there any library that can help me with it?
I'd suggest using Universal Tween Engine. You could add a short deleay and proper math equations to smooth out the camera transitions.
http://www.aurelienribon.com/blog/projects/universal-tween-engine/