Thanks for the info on that JD.
It's still now working for me. I added the code you mentioned but the bullets go in different directions. Somtimes shooting in the opposite direction. Maybe my trig that I'm doing is wrong? Here's my ccTouchesBegan code. The x1 and y1 variables are the x,y coordinates of the soldier on the screen.
'- (BOOL)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView: [touch view]];
point = [[Director sharedDirector] convertCoordinate: point];
NSLog(@"Clicked x=%f y=%f", point.x, point.y);
//x1 and y1 represent the place where the soldier is on the screen
double x1 = 150 ;
double y1 = 50;
double y2 = point.y;
double x2 = point.x;
double soldierAngle ;
if ( y2 < 50 && x2 <150)
{
//prevent from rotating past -90 degrees
soldierAngle = -90;
}
else if ( y2 < 50 && x2 >150)
{
// prevent from rotating past 90 degrees
soldierAngle = 90;
}
else if ( x2 < 150 )
{
//if user touched greater than 150
soldierAngle=atan ( (x1 - x2)/(y1-y2) ) * 180/PI ;
}
else if ( x2 > 150 )
{
//if user touched less than 180
soldierAngle = atan ( (x2-x1)/(y2-y1)) * 180/PI;
}
NSLog ( @"Soldier Angle is %f", soldierAngle ) ;
[soldier runAction:[RotateTo actionWithDuration:0.0
angle:soldierAngle]];
for(Bullet *b in bullets)
{
if([b ready])
{
[b fireFromTo:soldier.position.x y:soldier.position.y a:(CC_DEGREES_TO_RADIANS(-soldierAngle))];
[b setReady: NO];
break;
}
}
return kEventHandled;
}'