Tag Archives: ccpNormalize

How to shoot a bullet in the direction of touch in Box2D iphone?

By | January 30, 2011

write the below code in “ccTouchesBegan” function and you are done. Here the ballBody represents the bullet body. You can increase the power variable to increase bullet speed. [java] UITouch *touch = [touches anyObject]; CGPoint location = [touch locationInView:[touch view]]; location = [[CCDirector sharedDirector] convertToGL:location]; CGPoint shootVector = ccpSub(location, ball.position); CGFloat shootAngle = ccpToAngle(shootVector); CGPoint normalizedShootVector = ccpNormalize(shootVector);… Read More »