Skip to main content
GameDev.net gamedev.net
🔒 Locked

Particle Motion

Started by d9930380 Jun 10, 2002 at 5:39 AM 5 replies 1.3k views
Original Post
d9930380
d9930380
I want to be able to fire an object so that it lands exactly at another point in 3D space (when in the air - the only thing that will change the object''s velocity is gravity). What I need to be able to find is the initial velocity that the object must have. However the magnitude of this velocity will be capped, so it''s only the direction that I need to find. Any ideas on how this should be done.
VisualB4BigD
VisualB4BigD
This is pretty simple. I have the formula for Projectile Motion. All you have to do is rearrange the formula to find Inital Velocity. Then take that value and plug it back into the formula. Good Luck

Horny Farmer (Jolly Rancher)
dagarach
dagarach
capped, or fixed? if it is capped, you still need to find out the magnitude when lower than the cap.
d9930380
d9930380
Thanks for the replies.

The problem is to do that you need to know the time the projectile takes for the complete journey.

I don''t know this, I only know the magnitude of the initial velocity. If someone could tell me how I could use this to get t then I think I could take it from there.
powdahound
powdahound
Horizontal movement will only affect the distance. So here's how you do it:

Find the distance between the points (where you're starting and where yuo want to get to). And then find the vertical distance between the points.

You need to have 3 values to find the other two so you have: a = -9.8m/s2 (if you want to simulate earth's gravity). vf (final velocity) = 0m/s. d = whatever you calculated for vertical displacement. You want to find vi (initial velocity) and t (time in seconds).

vf2 = vi2 + 2ad
vi = sqrt(2ad - vf2)
since vf = 0
vi = sqrt(2ad)
so there you go, initial velocity

then for time:
d = vi*t + 0.5at2
(d - vi*t)/(0.5a) = t2
t = sqrt((d - vi*t)/(1/2a))

somebody correct me if i'm wrong. i just got up.

Gamer-Insight.com

[edited by - powdahound on June 10, 2002 12:31:10 PM]
danz
danz
ok, i''m gonna just post the results, if you want te entire way, just say so, i''ll be more than glad to post it.

so here is the thing:
we want to move the particle from the point A=(ax,ay,az) to the point B=(bx,by,bz).
we assume that the gravity is towards the nagative side of the z axis, we''ll call it g.
now, the "vertical" distance the particle should pass is : vd=bz-az
now in the motion equation : vd=0.5*g*t*t => t=sqrt(2*vd/g)=sqrt(2*(bz-az)/g)
the "horizontal" distance is : hd=(bx-ax)*sqrt(ax*ax+ay*ay)/ax
in the motion equation : hd=v*t => v=hd/t=((bx-ax)*sqrt(ax*ax+ay*ay))/(ax*sqrt(2*(bz-az)/g))
to get the vector, scale the vector u=(ax/sqrt(ax*ax+ay*ay),ay/(bx-ax)*sqrt(ax*ax+ay*ay)/ax,0) by the resulting v, V=u*v=((sqrt(g)*(bx-ax))/sqrt(2*(bz-az)),(sqrt(g)*(by-ay))/sqrt(2*(bz-az)),0)

that''s it! you can make this shorter if you call bx-ax=dx, by-ay=dy, bz-az=dz
so you get : V=(sqrt(g)*dx/sqrt(2*dz),sqrt(g)*dy/sqrt(2*dz),0)
you may precalculate sqrt(g)/sqrt(2*dz)=dzg, so V=(dzg*dx,dzg*dy,0)

voualla! simple heh?
danz
danz
as c code:

  
#define G 9.8

/*...*/

typedef struct{
float x[3];
}vector3f;

float getvelocity(vector3f a,vector3f b,vector3f *velocity){
float dx,dy,dz;
float time,invtime;
dx=b.x[0]-a.x[0];
dy=b.x[1]-a.x[1];
dz=b.x[2]-a.x[2];
time=sqrt(2*dz/G);
invtime=1/time;
velocity->x[0]=invtime*dx;
velocity->x[1]=invtime*dy;
velocity->x[2]=0;
return time;
}

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.