|
-
-
*bump* Somebody say something. This thread is getting one-sided.
-
hi
well an idea woudl be doing it like the binary search (guessing ) system does it.
1. let the tank shoot with some power and some angle
2. measure the distance to the target
3. figure out if you shot in front of the target or behind
4. increase/decrease power/anlge by some value
5. see point 1.
but i think this is only necessary when doing real high complex calculations WITHOUT knowing the influences of the environment to the projectile (wind,...) - yours is not that complex plus you know the exact position of the target. Just calculate the optimal shot using standard physics formula calculating a projectiles flight and reverse it. you "know" already where the bomb will fly to, what you want to know is how it flys there Well you might say then "okay, but there are 2 variables - angle AND power". Well, as u said: limit the calculation to find the necessary power for every angle until it hits. there are only 45 (or 90 if u use 0.5 angles too) different angles to work with, that should be no problem for any pc being pentium class.
So create a loop that increases both (power and angle) until it hits the target or shoots too far - when shot was too far keep angle but modify power.
Yours
HTD
BTW the angles needed are only "45 to 90" starting from the ground. u can also use 0 to 90 but i think this is unnecessary.
-
Here's an idea... havent quite worked it out yet... you could put everything in a while loop (while (_x<>targetx))or somethin like that.. for each time it loops through, you would find the rotation value using algebra, then store it in an array... once you are done looping through... call the rotation values from the array, for each frame... I hope that makes sense
-
Thanks for the ideas fellas. 
I meesed around bigtime with while loops the other day BC... nothing good came out of it with the inverse formula since they just changed all three values to fit in a non-possible solution...
Hehe, mr Duck hit the spot riht on. I don't know why, but I always come up with the great ideas when giving up and going to bed after a night of beating the script around.
Your solution is basicly what I worked out today!
I added about 200 lines of code to the enemy tank checking the last explosion coords and then increasing/decreasing angle/rotation depending on a bunch of things.
http://www.rydeman.com/erik/tanks3.html
Edit: Eeeep, just noticed a bug locking the game up on occasion! I'll see if I can find out what it is...
[Edited by Rydeman on 07-15-2001 at 07:09 PM]
-
bug fixed. I hate variable spelling errors...
-
Lookin good Rydeman... just wonderin how you did the destructable terrain.... I dont need actual source... just somethin to give me an idea. It could be very useful for games.
-
-
hi
just to make sure i understand this, you have two points and you want to know what combination of speed and angle will satisfy by passing through the two points. i did a similar thing a while back. however that was for a tennis ball passing through three points.
i will have a dig around and find the papers, and hopefully report a solution back soon.
matthew
-
hopefully this is what you need.
im sorry about the notation but its not easy with only the key board and there are no microsoft word symbols.
any how, heres a qucik introduction
say you have two dots as your tanks, find the x co-ordinate difference, and the y co-ordinate difference, i assume this is no problem
one more thing, for some reason flash kit does not like spaces at the begining of the line, so where i have used ` it is not to mean any thing, just to keep formating
| | represents a vector ie
| | = x component
| | = y component
|0|
|g| = a
intergrate the aceleration vector
|u |
|u-gt| = v
intergrate the velocity components
|ut |
|ut - 0.5gt*t| = r
this gives us the position vectors, bringing in sine and cosine
|utcos@ |
|utsin@ - 0.5*g*t*t| = r
this is the majority of what you need to be able to claculate the required velocty and angle of projection. but to make it more useful we need it as one equation, so here goes
x = utcos@ ... equation 1
y = utsin@ - 0.5*g*t*t ... equation 2
rearange equation 1 in terms of t
x/(ucos@) = t ... equation 3
sub equation 3 into equation 2
y = u*x*sin@`````````g*x*x
````---------- - ---------------
`````u*cos@ 2*u*u*cos@*cos@
simplifing gives
y = xtan@ -````g*x*x
```````````------------
``````````2*u*u*cos@*cos@
now if we reange in terms of u we get
2*u*u =````````-g*x*x
```````----------------------
````````y - x*tan@)*cos@*cos@
then by a further bit of simple rearaging we get
``u =`````````````-g*x*x
````````( ------------------------ )^0.5
````````2*(y - x*tan@)*cos@*cos@
hopefully i have not made any erros in the math there, but more its possible i have, ill check it latter just to make sure.
using the final equation this will give you the speed to hit the target for various angles.
i woud suggest setting priority speeds, so it starts at 50 unit speed than used the angle. if there is a mountian in the way than it agjusts the angle by say 10 degrees, and calcuates the required velocity of the bullet. this way it does not appear to perfect, and appears to have some inteligence
any way good luck, let me know if this is what you need, and how you get on.
sorry about the spelling 
matthew
-
-
Oh, the equation looks nice! I have yet to test it.
Slightly confused though, which part is ^0.5? all of the below part of the division (don't know what the name is in English)?
if this works it sure will come in handy! You have my deepest thanks!
-
I think the word is "remainder". I must say I'm totally impressed by the whole thing. Just like the orriginal but in my favoured medium. I would think that your system of 320 2px animated mc's would have taken you ages! Did you perhaps consider just using 4px square mcs and duplicating them?
Are you going to allow for caverns? Remmeber the original had cavern maps with a ceiling as well as a floor... how about rollers? (My personal favourite weapon).
-
^o.5 simply means raising the whole equation to the power of 0.5 this is the same as square rooting the whole equation
-
Yeah that's what maths says, but Flash thinks differently. 6^2 = 36 right?
not so according to Flash... I think it's actually an Xor gate. this gives what we wnat:
Code:
trace (Math.pow ( 6, 2 ));
-
the only reason i used the ^0.5 was because i did not have a suitable square root key on my key board
-
yeah yeah, I know that, I'm just pointin it out for Rydeman b/c it took me a while to figure out
-
hm... math is of course the best solution. But i thought in this case that's not necessary - that's why i posted a weird explanation of how he could do it instead of telling him to integrate his formulas to get the bomb-curve needed for any coordinates...
Again, the math way is the best - great work done here!!
Yours
HTD
-
-
no problem
im pleased it worked. i did some math along similar lines a while ago. only it was slightly more complicated, but very similar principles. i knew my maths would have some use after school, and flash is an excellent place for it D)
in the `thanks to` section you can use my reall name, Matthew Warneford, thanks
as a favour in return could you check out the site of the company i work for. its aim at teenagers, and we would love some feed back. http://www.dubit.co.uk depending on what time you go it will be very busy or quite. its busy around 8 pm uk time. or often during uk working hours thanks matthew
can you email me the game when youve finished it id love to see how you get along
thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|