Anybody know math?

Video Game Discussions and general topics.

Moderators: AArdvark, Ice Cream Jonsey

User avatar
pinback
Posts: 17849
Joined: Sat Apr 27, 2002 3:00 pm
Contact:

Anybody know math?

Post 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. =(
Am I a hero? I really can't say. But, yes.

User avatar
pinback
Posts: 17849
Joined: Sat Apr 27, 2002 3:00 pm
Contact:

Re: Anybody know math?

Post 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
Am I a hero? I really can't say. But, yes.

User avatar
AArdvark
Posts: 17735
Joined: Tue May 14, 2002 6:12 pm
Location: Rochester, NY

Re: Anybody know math?

Post by AArdvark »

This sounds like a calculus problem. Hum....

THE
NEWTON KNOWS
AARDVARK

User avatar
pinback
Posts: 17849
Joined: Sat Apr 27, 2002 3:00 pm
Contact:

Re: Anybody know math?

Post by pinback »

Yeah well I ain't learnin' that. I'm old and confused!
Am I a hero? I really can't say. But, yes.

Casual Observer
Posts: 3529
Joined: Wed Oct 01, 2003 10:23 pm
Location: Everett, WA, 2 blocks from where the Green River Killer picked them up

Re: Anybody know math?

Post by Casual Observer »

Amazon's got AI on demand for this kind of shit I think.

User avatar
pinback
Posts: 17849
Joined: Sat Apr 27, 2002 3:00 pm
Contact:

Re: Anybody know math?

Post 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.
Am I a hero? I really can't say. But, yes.

User avatar
Ice Cream Jonsey
Posts: 30067
Joined: Sat Apr 27, 2002 2:44 pm
Location: Colorado
Contact:

Re: Anybody know math?

Post by Ice Cream Jonsey »

It's getting spicy!!
the dark and gritty...Ice Cream Jonsey!

User avatar
Tdarcos
Posts: 9529
Joined: Fri May 16, 2008 9:25 am
Location: Arlington, Virginia
Contact:

Re: Anybody know math?

Post 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.
"Baby, I was afraid before
I'm not afraid, any more."
- Belinda Carlisle, Heaven Is A Place On Earth

User avatar
pinback
Posts: 17849
Joined: Sat Apr 27, 2002 3:00 pm
Contact:

Re: Anybody know math?

Post by pinback »

Okay, so we now have a name for it. We're halfway there!
Am I a hero? I really can't say. But, yes.

User avatar
AArdvark
Posts: 17735
Joined: Tue May 14, 2002 6:12 pm
Location: Rochester, NY

Re: Anybody know math?

Post 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.

Post Reply