Time for action – aiming at the touch position
Now that we can point where to shoot, let's make the hunter to aim at this point.
- Open the
Hunter.h
file and add theaimAtPoint:
method declaration:#import "CCSprite.h" @interface Hunter : CCSprite -(void)aimAtPoint:(CGPoint)point; @end
- Then, open the
Hunter.m
file and add the following methods below theinit
method:-(CGPoint)torsoCenterInWorldCoordinates { //1 CGPoint torsoCenterLocal = ccp(_torso.contentSize.width / 2.0f, _torso.contentSize.height / 2.0f); //2 CGPoint torsoCenterWorld = [_torso convertToWorldSpace:torsoCenterLocal]; return torsoCenterWorld; } -(float)calculateTorsoRotationToLookAtPoint: (CGPoint)targetPoint { //1 CGPoint torsoCenterWorld = [self torsoCenterInWorldCoordinates]; //2 CGPoint pointStraightAhead = ccp(torsoCenterWorld.x + 1.0f, torsoCenterWorld.y); //3 CGPoint forwardVector = ccpSub(pointStraightAhead, torsoCenterWorld...