-
Odds of a hit?
I would like to ask for for some help with a game I'm making. I have a computer controlled cannon the fires (cannon ball) back at the players castle,.but it's not very accurate. I have the computer controlled cannon setting it's angle before firing, but I want it to hit it's target randomly. Like the odds of it hitting it's target it 1 out of 5 or whatever..
I hope I explained this right. Anyone have any ideas?
-
Calculate the correct angle to hit the castle and then subtract 5 add random(10). This will give it a random chance between + 5 and - 5 degrees accuracy.
-
You could do this in numerous ways. Not knowing how your game works, it is hard to know which method works for you.
Here is one suggestion:
Set angle to correctAngle + (random(5)*5)-10
If the correct angle is 45, this will set the angle to either 35,40,45,50 or 55.
-
Chris,..Thank you. I give this a shot. Can I ask how this would written out?
-
Is it side view or top down?
Does the cannon ball shoot directly straight, or does it fire up into the air and then fall down with gravity?
-
1 Attachment(s)
Popcorn and Chris,
Here's the game MFA,.the computer controlled part needs to be changed. This is the part that I'm having trouble with. Cannon 1 (player) Left mouse sets the power of the cannon ball speed and right mouse fires it. The code is a mess with the computer controlled cannon at this point,.so don't laugh. I have changed it since this,.but I don't have the file with me today. I have the other cannon firing by pressing M to set angle and L to fire it right now. If you guys want me to upload the other version,.it will have to wait until tomorrow. But,.you'll see what I'm looking to do with this ,.and if you feel like fixing the other cannon,.it would be appreciated as I would like this to be a playable game and the odds of hitting the other target I just can't get my head around. The graphics are being changed too. Instead of rocks being around the characters,.there will be castles that each hit taken by a cannon ball will destroy a little bit of the castle.
Thanks guys for taking a look at this.
-
Just wanted to say thank you to both you guys. It worked out perfect with you methods after some tweaking.