Page 1 of 1

Anybody know math?

Posted: Sat Dec 18, 2021 1:15 pm
by pinback
I have a problem I need to solve for my game (see Jolt Country Game Development forum.) I can do basic stuff like figuring out distances and angles, but this one is above my paygrade.

I'm not above just copying a bunch of code/pseudocode and refitting it for the language I'm using, but I'd kinda sorta like to understand it if it's something someone can explain to me.

Basically, I wanna (on a 2D plane) have the player fire a (non-homing) bullet at a moving target and hit it (assuming it doesn't change direction or speed.)

I know my location. I know the moving target's location, direction and speed of movement. I know how fast the bullet is going to go. I just need to know which direction to fire it to make sure they intersect.

I never learned math. =(

Re: Anybody know math?

Posted: Sat Dec 18, 2021 1:23 pm
by pinback
Okay I've found this link which lays out a block of Javascript that it says it does what I want.

Looking at the code, I am 100% sure there is no way I'd ever understand it unless I took a course in whatever math this is.

Copy and paste it is!

https://stackoverflow.com/questions/224 ... tile-and-u

Re: Anybody know math?

Posted: Sat Dec 18, 2021 1:25 pm
by AArdvark
This sounds like a calculus problem. Hum....

THE
NEWTON KNOWS
AARDVARK

Re: Anybody know math?

Posted: Sat Dec 18, 2021 2:35 pm
by pinback
Yeah well I ain't learnin' that. I'm old and confused!

Re: Anybody know math?

Posted: Sat Dec 18, 2021 8:07 pm
by Casual Observer
Amazon's got AI on demand for this kind of shit I think.

Re: Anybody know math?

Posted: Sun Dec 19, 2021 11:34 am
by pinback
Casual Observer wrote: Sat Dec 18, 2021 8:07 pm Amazon's got AI on demand for this kind of shit I think.
This is a great idea, I hadn't thought of that! Every time the player hits the fire button, I'll just fire off a request to AWS.

Cross-region load balanced, of course. I don't want players to be searching up "photon torpedo" on downdetector.com.

Re: Anybody know math?

Posted: Sun Dec 19, 2021 11:47 am
by Ice Cream Jonsey
It's getting spicy!!

Re: Anybody know math?

Posted: Mon Dec 20, 2021 6:09 am
by Tdarcos
I believe the term you're looking for is "slope-intercept form." It's used in the calculation of ballistic trajectories, which is what you need when firing (or aiming) one moving thing (projectile) at another moving thing (target). You're trying to discover the straight line from where you are firing that gets the projectile to the destination where the target will be at when the projectile will arrive.

Because the distance and speed determine where the projectile will be at any specific time, the same calculation has to be made for the target. You connect how far it can move then you adjust how far in front of the target you aim to hit it on arrival.

Let's take an example, you're an assassin, trying to shoot a politician on a parade float. The float will move at 5 mph, or 7.333(repeating) feet per second. Your rifle fires a bullet at 1200 fps. If you're 300 yards away, or 900 feet, the bullet will take 9/12 of one second to arrive, or 0.75 seconds, so the target will move 5.4 feet in the time it takes for the bullet to travel 900 ft. Well, if you aim straight at him, you'll miss his head by that much. So you need to know what tiny amount of movement of the rifle left compensates for the difference in distance. At this distance the extra time for the bullet to travel the increased distance diagonally is negligible, but if you're firing a 30" naval gun at a plane moving at 300 mph, you have to compensate for that, too; These are the things the slope-intercept calculations tell you.

In fact, calculating ballistic trajectories is the reason we have computers today. The government funded research on machines that could do ballistics. Computers came from that need.

Re: Anybody know math?

Posted: Mon Dec 20, 2021 6:59 am
by pinback
Okay, so we now have a name for it. We're halfway there!

Re: Anybody know math?

Posted: Mon Dec 20, 2021 8:17 am
by AArdvark
Commander could have scored an A+ on that post if he had made it a presidential limo in Dallas instead of a parade float.