Projectile Problem
Here''s a question for someone that has a better knowledge of trig etc than i do...
I have 2 points, one at (a.x,a.y) and the other at (b.x,b.y)
They can be anywhere on the screen
I want to fire a projectile from point a to point b
The projectile will have an x speed and a y speed.
How do i find what the x speed and y speed of the projectile should be?
I''m not worried about how fast the projectile travels, as once i have the speed values, they can be multiplied by the same factor to speed it up.
----
Gareth Williams
gareth@fatweb.org
----
----Gareth Williamsgareth@fatweb.orgwww.fatweb.org----
So, we have two points:
and you want two components of velocity (x and y) such that a projectile with those velocity components will travel from A to B.
This is very easy:
Total x distance = b.x - a.x
Total y distance = b.y - a.y
Total linear distance = sqrt(((b.x - a.x) * (b.x - a.x)) + ((b.y - a.y) * (b.y - a.y)))
So in order to get your projectile to travel from A to B you need to set
projectile.xSpeed = (xDistance/linearDistance) * projectileSpeed
projectile.ySpeed = (yDistance/linearDistance) * projectileSpeed
I hope I haven't made any glaring mistakes!
EDIT: html tag brackets wrong
Edited by - Enigma on October 26, 2001 7:22:37 AM
A B
and you want two components of velocity (x and y) such that a projectile with those velocity components will travel from A to B.
This is very easy:
Total x distance = b.x - a.x
Total y distance = b.y - a.y
Total linear distance = sqrt(((b.x - a.x) * (b.x - a.x)) + ((b.y - a.y) * (b.y - a.y)))
So in order to get your projectile to travel from A to B you need to set
projectile.xSpeed = (xDistance/linearDistance) * projectileSpeed
projectile.ySpeed = (yDistance/linearDistance) * projectileSpeed
I hope I haven't made any glaring mistakes!
EDIT: html tag brackets wrong
Edited by - Enigma on October 26, 2001 7:22:37 AM
Thanks alot!
I knew it would be simple really, but I just lack the ability to be able to think mathematically beyond a certain level of difficulty
It''s gonna make learning more complicated 3D stuff nigh on impossible :/
Oh, uhhh, check out the project this applies to
Thanks again
----
Gareth Williams
gareth@fatweb.org
----
I knew it would be simple really, but I just lack the ability to be able to think mathematically beyond a certain level of difficulty

It''s gonna make learning more complicated 3D stuff nigh on impossible :/
Oh, uhhh, check out the project this applies to

Thanks again
----
Gareth Williams
gareth@fatweb.org
----
----Gareth Williamsgareth@fatweb.orgwww.fatweb.org----
LOL I just noticed that this is simple pythagorus!
Damn easy when you think about it
----
Gareth Williams
gareth@fatweb.org
----
Damn easy when you think about it

----
Gareth Williams
gareth@fatweb.org
----
----Gareth Williamsgareth@fatweb.orgwww.fatweb.org----
xspeed = sin(angle) * speed;
yspeed = cos(angle) * speed;
object.x += xspeed;
object.y += yspeed;
Some simple trig pseudocode
yspeed = cos(angle) * speed;
object.x += xspeed;
object.y += yspeed;
Some simple trig pseudocode

-----------------------"When I have a problem on an Nvidia, I assume that it is my fault. With anyone else's drivers, I assume it is their fault" - John Carmack
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement