Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / Calculates angle to hit any point within range based on gravity, velocity, x and y.

Author
Message
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 17th Jul 2006 16:00 Edited at: 17th Jul 2006 16:02
This will calculate the angle based on the above. You can choose whether you want a lob shot or a direct shot. This does not use trial and error, but instead uses complex mathematics which you might not understand, and I didn't understand until I made this. It's very useful for a targeting system.




^
run in 640*480 mode
just copy+paste
No media

Up/Down to change velocity.
Left/Right to select Lob or Direct.
Space to shoot.
Bullet will hit mouse coordinates

If angle goes to infinity, it means that the target is out of range, so you must increase the velocity.

I hope you like it, and find it useful. I certainly have

There are three types of people, those that can count and those that can't.
sadsack
20
Years of Service
User Offline
Joined: 27th Nov 2003
Location: here
Posted: 18th Jul 2006 02:01
very nice, i like it and it works good.
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 18th Jul 2006 11:39
Thanks, David T helped me a lot as well though

There are three types of people, those that can count and those that can't.
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 18th Jul 2006 11:40 Edited at: 18th Jul 2006 11:40
Don't you think you ought to credit DavidT for this?
Without his maths help this just wouldn't do anything.

[Edit] You beat me to it


Xander
21
Years of Service
User Offline
Joined: 3rd Mar 2003
Location: In college...yeah!
Posted: 4th Aug 2006 20:36
This is really usefull, I think I will use it for artilery for Firewall 2. But I think I will switch around the formulas to always have a specified angle, and determine the needed velocity to hit the target. That'd be pretty cool... Thanks!

Xander Moser - Bolt Software - Firewall
Xenocythe
19
Years of Service
User Offline
Joined: 26th May 2005
Location: You Essay.
Posted: 5th Aug 2006 03:42
Wow, mind if I make a little game snippet out of this?

Applyby has Flies in his Eyes.
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 5th Aug 2006 10:51
Use it however you want.

There are three types of people, those that can count and those that can't.

Login to post a reply

Server time is: 2024-11-23 03:31:47
Your offset time is: 2024-11-23 03:31:47