projectiles
I am trying to have an arrow move from the player's position toward the enemy's. I'll know the x and y values of both at that point, so I just need each point that makes up the line to the enemy's position. I know I should know this, but I just can't seem to remember who to do it. I think it would have something to do with y=mx+b, maybe?
Although, I can't remember how to get the slope (m) either...I'm forgetting all my algebra...
Any help would be appreciated
Edited by - Nazrix on 4/27/00 2:56:57 PM
Need help? Well, go FAQ yourself. "Just don't look at the hole." -- Unspoken_Magi
Well, you would have to calculate the slope even though you don''t like it. You could also use Brensemham''s (however you spell it ) algorithm and alter it to be able to use it with the projectile. y = mx + b is the slope formula (as you have pointed out). m is the rise over run, and b is the y-intercept. others will help fill in the gaps, since im on the run right now .
y = mx+b is slope-intercept form (where m is the slope and b is a constant)
To find m, here''s the eq:
m = (y2-y1)/(x2-x1)
Actually, it really doesn''t matter which set of variables comes first as long as they line up (i.e., you can''t have y2 be first on the top and x1 first on the bottom)
If you code it, they will come...
Commander M
http://commanderm.8m.com
cmndrm@commanderm.8m.com
To find m, here''s the eq:
m = (y2-y1)/(x2-x1)
Actually, it really doesn''t matter which set of variables comes first as long as they line up (i.e., you can''t have y2 be first on the top and x1 first on the bottom)
If you code it, they will come...
Commander M
http://commanderm.8m.com
cmndrm@commanderm.8m.com
April 27, 2000 03:31 PM
Given two points (x1,y1) and (x2,y2) (I assume you are working in two dimensions here) you can find the points in between these two points as follows.
Using the parametric form of a line which is:
x = x1 + (x2-x1)t
y = y1 + (y2-y1)t
where t is a value between 0 and 1, which represents how far along the line you are.
For example, if you wanted to find the point exactly half way in between pt1 and pt2, you would use a value of 0.5 for t.
So if you wanted to shoot a bullet of at an enemy at (x2,y1), when you are at (x1,y1) just use the above equation, adding some value to t until it reaches 1.
PreManDrake
Using the parametric form of a line which is:
x = x1 + (x2-x1)t
y = y1 + (y2-y1)t
where t is a value between 0 and 1, which represents how far along the line you are.
For example, if you wanted to find the point exactly half way in between pt1 and pt2, you would use a value of 0.5 for t.
So if you wanted to shoot a bullet of at an enemy at (x2,y1), when you are at (x1,y1) just use the above equation, adding some value to t until it reaches 1.
PreManDrake
Forgot to mention, if you are working in 3 dimensions the third part is:
z = z1 + (z2-z1)t
PreManDrake
z = z1 + (z2-z1)t
PreManDrake
It''s also better to use parametric equations. If you use the y=mx+b formula, there is one special case you can''t do: vertical lines give m=1/0... which is a bad thing. You will notice that the parametric equations also turn nicely into vectors. Let A be the vector of the initial placement, B be the vector of the destination, and t be the same time, you end up with current position= A+(B-A)*t
(B-A) is the velocity vector.
(B-A) is the velocity vector.
The parametric equation does look much better, but if I''m understanding this correctly, if I increase T by like .1 or so each time then the X and Y coordinates will have decimals in them. How would I round them up or down to a whole number? Is there a function for that already?
Thanks again
Thanks again
Need help? Well, go FAQ yourself. "Just don't look at the hole." -- Unspoken_Magi
As LaMonthe mentions in Tricks of the Windows Game Programming Gurus, there is an algorithm for doing this. It doesn''t exactly round anything up or down, but it finds the best fitting line using an error offset. This is normally used for vector games such as the original Asteroids. I didn''t exactly understand how he explained the algorithm, but maybe someone else can help you out.
"Remember, I'm the monkey, and you're the cheese grater. So no messing around."
-Grand Theft Auto, London
"It's not whether I win or lose, as long as I piss you off"
-Morrigan, Super Puzzle Fighter II Turbo
"Remember, I'm the monkey, and you're the cheese grater. So no messing around."
-Grand Theft Auto, London
"It's not whether I win or lose, as long as I piss you off"
-Morrigan, Super Puzzle Fighter II Turbo
D:
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement