I am developing a game using Sprite-Kit (Objective-C). It\'s a game where you control a bird in flight and arrows and other bad projectiles are shot at you from the right/to
The basic steps are
Here's an example of how to do that
Obj-C
// Calculate vector components x and y
CGFloat dx = bird.position.x - launcher.position.x;
CGFloat dy = bird.position.y - launcher.position.y;
// Normalize the components
CGFloat magnitude = sqrt(dx*dx+dy*dy);
dx /= magnitude;
dy /= magnitude;
// Create a vector in the direction of the bird
CGVector vector = CGVectorMake(strength*dx, strength*dy);
// Apply impulse
[projectile.physicsBody applyImpulse:vector];
Swift
// Calculate vector components x and y
var dx = bird.position.x - launcher.position.x
var dy = bird.position.y - launcher.position.y
// Normalize the components
let magnitude = sqrt(dx*dx+dy*dy)
dx /= magnitude
dy /= magnitude
// Create a vector in the direction of the bird
let vector = CGVector(dx:strength*dx, dy:strength*dy)
// Apply impulse
projectile.physicsBody?.applyImpulse(vector)