[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
ok so I'm trying game maker and I'd like to have a
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /wsr/ - Worksafe Requests

Thread replies: 20
Thread images: 5
File: FUCK MAN.png (18 KB, 694x655) Image search: [Google]
FUCK MAN.png
18 KB, 694x655
ok so I'm trying game maker and I'd like to have a projectile intelligently shot where I'm GONNA be instead of where I currently am, right, but I'm busting a nut over the pure math of it, like I'm in calc and this is still hard as shit no matter how many equations I consider

pic related, here's the variables

X and Y: the location where player and projectile meet
Xo and Yo: the initial point of the player
X'o and Y'o: the initial point of the projectile
s and s': the speed of the player and projectile respectively (the projectile will be much faster typically)
θ and θ': angle of the player and projectile (for GM's sake, relative to the x-axis)
t: seconds

I've tried looking at it as a triangle even, but these starting equations are important

X = Xo + ts(cosθ) = X'o + ts'(cosθ')
Y = Yo + ts(sinθ) = Y'o + ts'(sinθ')

who else dumb as fuck
>>
oh yeah, so the variables we don't know are θ' (which we can change), X and Y, and t

speed and starting points will be already set

all I really need to find is θ'
>>
we're finding where to aim the gun, think back to like TF2 and firing a rocket at a dude, except he moves in a straight line with constant velocity
>>
oh yeah, if the bullet were to move slower than the player, then that would mean there are some cases where the bullet will never catch up no matter what, so that could maybe show in a final equation if s' is less than s resulting in like an imaginary number
>>
oh yeah, a solution for θ' would have to be in terms of the variables we already know (Xo Yo X'o Y'o s s' θ)
>>
>>76892
You're overthinking this.

The player can't to any real extent influence the closing time of the projectile (if he could, he could run away from it Benny-Hill style), so you don't need to consider that.

Just work out the closing time from the distance, then the x/y component of the velocity of the player wrt to the aim vector multiplied by the closing time is how much you need to lead.

If you have historical movement data (or can cheat by reading the player entity's fields), then you can use his acceleration for better accuracy.
>>
File: boy.jpg (196 KB, 1179x1280) Image search: [Google]
boy.jpg
196 KB, 1179x1280
>>76912
well obviously it would be the goal of the player to change course once he sees the missile is going to collide with him..?

I'm sure the words you're saying have meaning, but please consider the fact that I'm dumb as fuck

whaddya mean closing time and velocity of the player with respect to the gun's aim vector? and historical movement data and entity fields and what
I'm new to GM obviously

I could always try to cheap my way out of this problem by having a guesstimation program or just shoot some other way by giving the player a 2 second warning but I wanna wait til after I give up on this to do that
>>
>>76920
>whaddya mean closing time and velocity of the player with respect to the gun's aim vector
You know what a vector is, right?

So the aim vector is just the vector between the shooter and the target.

If you transform the coordinates of the shooter and the target to the aim vector, you've now got the aim vector lined up with one of the axes. Let's call that one the Z axis for simplicity.

This helps, because now the Z axis and the XY axes do completely different things and can be considered separately.

The projectile travels along the Z axis, so the distance along the Z axis divided by the projectile's speed is the time it'll take the projectile to get there. Let's call that Tp.

Now, the player's going to try to dodge. The crucial insight is that regardless of whether the player dodges forward, backward or sideways, he really can't make that much difference to Tp, so we can ignore that entire facet of the calculation, and simplify the math significantly.

We've now reduced the problem to a simple linear calculation: given the player's velocity, and the time Tp, work out where the player will be. Just take the player's movement vector, transform it to the aim vector, normalise it, and multiply it by Tp, and that's where the player will be at the time of impact if he keeps going at that speed in that direction.*

If you know the player's position a few frames ago, or can find out the player's acceleration directly, you can also use that for more accuracy. Don't bother working in three dimensions, just calculate in one dimension then scale Tp.

* This is how AA gunsights worked in WWII: the expected range is input, and from that the distance and flight time can be worked out. The gun knows the distance and how fast it's traversing, and therefore how fast the target is moving. This is enough information to do the above calculation and project a crosshair with the right amount of lead. In WWII, they did this with analogue computers made from pulleys and belts.
>>
>>76957
>So the aim vector is just the vector between the shooter and the target.
>If you transform the coordinates of the shooter and the target to the aim vector, you've now got the aim vector lined up with one of the axes

the funny thing is, I don't know where the target is. that's what I'm trying to find. I'm assuming you mean X and Y. that's probably wrong though

I know what vectors are. My big issue with understanding is that you're making terms far beyond the scope of the problem I described. Maybe an illustration would help?

>given the player's velocity, and the time Tp, work out where the player will be. Just take the player's movement vector, transform it to the aim vector, normalise it, and multiply it by Tp, and that's where the player will be at the time of impact if he keeps going at that speed in that direction

I'm assuming you're adding the aim vector and scaled player vector?
>>
>>77005
>the funny thing is, I don't know where the target is.
Where the target is at the moment.

If you were firing a hitscan weapon, the vector you'd fire it along.
>>
File: 1-20-2015 4-44-06 PM.png (22 KB, 96x136) Image search: [Google]
1-20-2015 4-44-06 PM.png
22 KB, 96x136
>>77012
the target is a vector of where the gun is aimed

>So the aim vector is just the vector between the shooter and the target.

the vector between the point (Xo,Yo) and.. another vector? is the aim vector just the target then?

I shouldn't bother asking about the rest because it's clear I'm at a fundamental misunderstanding
>>
I don't know if I'm right or wrong, but I'm getting the following:
θ' = arccos((X - X'o) / (t * s')) = arcsin((Y - Y'o) / (t * s'))
>>
>>77295
I've probably gotten to that equation before
the problem with it is that we don't know what X and Y are gonna be, so if there was something else to substitute them with, that'd be gucci
guhjgjoiujiunj
>>
>>77510
You do know what X and Y are gonna be for a given t.
It's right there in your identities:
X = Xo + ts(cosθ)
Y = Yo + ts(sinθ)
s is known and assumed constant, as is θ, and t is chosen arbitrarily beforehand. Let's say t=1, when you want the projectile to go where the player character is supposed to be in one second.
>>
>>77516
t can't be chosen arbitrarily because the projectile speed is constant, meaning it won't necessarily get there in one second
>>
File: szsz.png (20 KB, 965x526) Image search: [Google]
szsz.png
20 KB, 965x526
>>77535
I think you're saying it wrong, but I get what you mean.

Here's a diagram which might help you think of a different approach:
The red spot is the player character. The blue circle represents where the player character may be after, say, one second of movement, while the pink line shows where the PC is actually going.
The green spot is where your gun is, and the yellow circle is where the bullets can reach in the same one second.
This means that the radiuses of the circles are equal to the speed of your entities, multiplied by a given time.
In case 1, the PC is going exactly towards an intersection of both circles, so if the bullet is shot in the direction of the brown line, the effect you want will happen, i.e. there is a solution.
In case 2, the PC and the gun are too far away from each other, so there can be no solution for the given time.
In case 3, the circles have intersections, but the PC is not going towards one of those, so there is no solution. In that particular case, more time is needed.

So, your strategy would be: find all times where the two circles have at least one intersection point, and among those times, find the one and only time when the player's assumed position for that time is the same as an intersection point.
>>
>>77568
*circumferences, not circles.
>>
>>77535
Yes it can, because you know the distance, you know the speed, and there's nothing the player can do to change the distance by any amount worth worrying about.

>>77020
it's the vector between
>Xo and Yo: the initial point of the player
and
>X'o and Y'o: the initial point of the projectile
>>
File: tmp2.png (23 KB, 796x526) Image search: [Google]
tmp2.png
23 KB, 796x526
Here is the "final solution", so to speak.
In this diagram, S and $ are the absolute speeds of your player character and projectile, respectively.
You find out if a suitable time exists, and what it is, by solving the quadratic equation at the bottom of this diagram.
Knowing the time, you can easily find out the point in question, the (X,Y), by using the identities at the top of the diagram.
Knowing (X,Y), you can easily calculate the angle.
>>
>>77699
Whoops, the identities are wrong.
They are actually
X = C + ...
Y = D + ...
Thread replies: 20
Thread images: 5

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.