Cannon AI, calculating angle.
Ok, well I can't get my second player OR my CPU player to work now. I decided to give the CPU a try since I ran into trouble doing player 2.
The problem here is, I can't get the CPU to calculate the angle of trajectory to fire at the player. I'm using the standard formula:
(1/2)*asin(9.81* self.Distance from / self.Power ^2)
The problem is, it keeps setting the angle to zero.
Anyone know why this is happening?
I'm trying to get the AI to calculate the angle to aim the shot from the bottom right corner to the player, which is in the bottom left.
The problem here is, I can't get the CPU to calculate the angle of trajectory to fire at the player. I'm using the standard formula:
(1/2)*asin(9.81* self.Distance from / self.Power ^2)
The problem is, it keeps setting the angle to zero.
Anyone know why this is happening?
I'm trying to get the AI to calculate the angle to aim the shot from the bottom right corner to the player, which is in the bottom left.
Comments
I use a lot of rotations in my game.
I have never used anything similar to the function you just stated
Actually for the first time, this didn't really help... See I'm trying to create a CPU AI to calculate where the player is and form an arc based on that. In this case, there's no mouse x or mouse y (used in the orbz demo) for the CPU to get since it's auto aiming for the player, the playing isn't aiming the CPU
Try testing out the expression with numbers that you know will work and then see if you get the correct result. (For example, I just plugged in "DistanceFrom = 200" and "Power = 100" into your equation and got a result of 5.65742. Do you get the same?
Try plugging in the numbers I gave you and see if you get the same result.
I put the following behaviors in an actor --
Change Attribute: self.distanceFrom To: 200
Change Attribute: self.Power To: 100
Change Attribute: self.angleOfTrajectory To: (1/2)*asin(9.81* self.distanceFrom / self.Power ^2)
Display Text: self.angleOfTrajectory
I get 5.65742 in the display text.
If I change the angleOfTrajectory equation by removing the asin() function so that it reads: (.981* self.distanceFrom / self.Power ^2)
I get .01962
If I change the angleOfTrajectory equation to: (.981* self.distanceFrom / self.Power ^2)
I get 1.12422
Are you getting similar numbers?
That being said a problem still remains. The distance between my two players is around 2000, now the CPU cannon's angle is practically straight up in the air, so there's still something wrong with my numbers. It might help if I provide some more data.
My stage is 2400px so the distance between the two cannons is around 2000px. I currently have the power set to 600 for both cannons and the gravity on the projectile is 120.
Changing the gravity to 120, however makes the CPU cannon spin until the cows come home, never reaching an angle, presumably because it's huge.
You're a miracle worker TSB seriously! I tried this before when mu-kow suggested switching the two values, but it didn't work for some reason. Maybe I just needed sleep...
Thanks again.