I am having an issue with the computer firing back a cannon ball. It keeps hitting the hill. In the photo the 2 red "X"'s are located at the cannon ball start, or the object.frame.origin.x and y. I wanted to make sure my 2 points were correct. You can also see the cannon ball striking the frame of the hill.
When I researched this it was the slope, or RISE over RUN. I built a method to convert the slope to degrees. In the RISE it was normally Y2 - Y1 but since Apple screen coordinates start at the top and work down they were reserved, so I flipped them to Y1- Y2. Other wise it was shooting backwards of something.
Once that Method is called it adds a velocity executes the fire method. located here which basicly just converts the Degrees to Radians.
The Objects values at the time of the calculations are "Red X's"
Which gives me a degree value of 29.619 before converting to Radians which is .516956
I can see with my own eyes that 29 degrees is lower then it should be. It looks closer to 45 give or take.
Any help would he appreciated.
When I researched this it was the slope, or RISE over RUN. I built a method to convert the slope to degrees. In the RISE it was normally Y2 - Y1 but since Apple screen coordinates start at the top and work down they were reserved, so I flipped them to Y1- Y2. Other wise it was shooting backwards of something.
Code:
#define PI 3.1415926536
-(float)collectDataForShot_Castel:(NSMutableDictionary*)data{
CGPoint canXY = canRect.origin;
CGPoint hilXY = hillRect.origin;
float rise = (canXY.y - hilXY.y);
float run = hilXY.x - canXY.x;
float degree = atan2(rise,run) * 180 / PI;
return degree;
}
Once that Method is called it adds a velocity executes the fire method. located here which basicly just converts the Degrees to Radians.
Code:
-(void)fireCannonBall{
openFinished = YES;
incomingSoundPlayed = NO;
if (userTurn) {
[velSlider setHidden:YES];
[angSlider setHidden:YES];
[readyButton setEnabled:NO];
[readyButton setHidden:YES];
[fireButton setEnabled:NO];
[fireButton setHidden:YES];
angle_R *= 3.1415926536 / 180; //Convert to radians
}
else{
angle_L *= 3.1415926536 / 180; //Convert to radians
}
[cannonAudio play];
}
The Objects values at the time of the calculations are "Red X's"
Cannon Ball start = x321 - y 292.
Hill is x518 - y180
rise totals = 112
run total = 197
Which gives me a degree value of 29.619 before converting to Radians which is .516956
I can see with my own eyes that 29 degrees is lower then it should be. It looks closer to 45 give or take.
Any help would he appreciated.