Projectile over a wall calculation?

BlitzMax Forums/BlitzMax Programming/Projectile over a wall calculation?

therevills(Posted 2010) [#1]
Hi All,

Does any one know how to do this?

I know the following:

* Start x,y
* End x,y
* Gravity
* Height of the wall

Diagrams:

....................wall
____s______|__________e_________


_s_|
......|
......|
......|_e_

etc

Any ideas?

Thanks!


matibee(Posted 2010) [#2]
I've never bothered trying to solve this directly. Run your projectile code with guestimates until you get close enough to the end point. With half-testing it's pretty quick to narrow down eg:

plugin "100" as start force.. too far? Try "50" too far? Try "25", too far try "12.5" not far enough? Try "18.75", not far enough? Try "21.875"... etc.

You'll have it within a few iterations. Your projectile code should know to exit with a failure once it passes end x.

Cheers!


ImaginaryHuman(Posted 2010) [#3]
Yeah I'm not sure how you'd exactly calculate it since you have to take into account the movement of the projectile over time.. I think I would do the same thing as matibee, some kind of binary subdivision/search doing lots of `tries` until you get very close.


GfK(Posted 2010) [#4]
Warpy posted some code quite recently to do exactly this when somebody else asked the same question....

[edit] My bad - he wrote a blog post on the subject. But its got code in and explains it well enough. Even I [almost] understood it.

http://www.blitzbasic.com/Community/posts.php?topic=87250


therevills(Posted 2010) [#5]
I did find that post of Warpy's, but it just made my brain feel like mush... :/

With Warpy's way I couldnt get it to fire the projectile up if the target was lower that than the start

I also found this one in the code archives:

http://www.blitzbasic.co.nz/codearcs/codearcs.php?code=1354

Converted it to BlitzMax (gee that was hard ;))


But I cant seem to move the starting x,y....


Nate the Great(Posted 2010) [#6]
well if you cant use the starting x,y then just make the calculations relative. So subtract the starting x and y from the target x and y and then use those as your target from the origin, get the angle to fire and then fire away.


Warpy(Posted 2010) [#7]
I was trying to remember if I'd written a post about this before, thanks for reminding me GfK.

Here's a post about your problem, therevills.


therevills(Posted 2010) [#8]
Thanks for that Warpy.

Could you get it so it works on the second diagram?:

......... |
__s__|
......... |
......... |
......... |___e___

Also why do you do minus 300 for the y? Is it to make it zero based?

	y#=MouseY()-300


Also how would I use the same code to do the other way:

___e_____|_____s____


........|________s_____
........|
........|
_e__|

Many thanks!


therevills(Posted 2010) [#9]
After a lot of messing around (god I hate this kind of math stuff!), think Ive got it how I want it:



I found this from a post Grey Alien made:

http://www.blitzbasic.com/Community/posts.php?topic=68027#759989

Thanks again for the help guys, much appreciated :)