Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Applying vector forces

2 views
Skip to first unread message

John Mancine

unread,
Jul 19, 1998, 3:00:00 AM7/19/98
to
Right now I am working on explosions in my game and I want to have the the
explosion 'push' each entity around.

I need to be able to apply a vector force to the current velocity vector of
each THING that is effected by the 'push' of the explosion.

I haven't had a ton of math.. but I can do this on paper relatively easily.
Law of sines/cosines etc etc... and it seemed to be pretty easy to throw
into the code, but I'm a little confused. Do I have to worry about what
quadrent each angle is in and stuff like that???
I'm just overall a little lost on how to make the transition from paper to
code...
If you can help, I would really appreciate it. Or maybe someone has code or
a link to a code example?

Thanks
..........................
John R. Mancine


Link

unread,
Jul 20, 1998, 3:00:00 AM7/20/98
to
John Mancine wrote in message <35b26...@news.amaesd.k12.mi.us>...


Here's a simple method:

vPush.x = objPos.x - exploPos.x;
vPush.y = objPos.y - exploPos.y;
vPush.z = objPos.z - exploPos.z;

Now vPush has the the directional vector of the explosion force. You could
then scale that by the distance from the explosion, the force of the
explosion, and the mass of the object being pushed. Then you can add that
vector to the object's velocity vector. A simple case like this shouldn't
require any trig, really...

- Mike


John Mancine

unread,
Jul 20, 1998, 3:00:00 AM7/20/98
to
>Here's a simple method:
>
>vPush.x = objPos.x - exploPos.x;
>vPush.y = objPos.y - exploPos.y;
>vPush.z = objPos.z - exploPos.z;
>
>Now vPush has the the directional vector of the explosion force. You could
>then scale that by the distance from the explosion, the force of the
>explosion, and the mass of the object being pushed. Then you can add that
>vector to the object's velocity vector. A simple case like this shouldn't
>require any trig, really...


Arrgghh! So I was just making this a LOT more complicated? Ughhh...

Thanks for the help. I'm going to go see what I can do with that.

thanks,
John Mancine

Darren Ranalli

unread,
Jul 20, 1998, 3:00:00 AM7/20/98
to
On Sun, 19 Jul 1998, John Mancine wrote:

> Right now I am working on explosions in my game and I want to have the the
> explosion 'push' each entity around.
>
> I need to be able to apply a vector force to the current velocity vector of
> each THING that is effected by the 'push' of the explosion.

Calculate the vector from the explosion to the object, and apply a force
in that direction to the object. The magnitude of the force should depend
on the power of the explosion and the distance between the explosion and
the object.

Darren Ranalli
http://www.wpi.edu/~dranalli/

TSheehan

unread,
Jul 20, 1998, 3:00:00 AM7/20/98
to
>vPush.x = objPos.x - exploPos.x;
>vPush.y = objPos.y - exploPos.y;
>vPush.z = objPos.z - exploPos.z;

Don't forget to normalize that vector, otherwise things
farther away will be _more_ affected. If you want the
force to fall of linearly with the distance, you can avoid
the square root:

fx = ObjX - ExpX;
fy = ObjY - ExpY;
fz = ObjZ - ExpZ;
DisSquared = fx*fx + fy*fy + fz*fz;
fx /= DisSquared;
fy /= DisSquared;
fz /= DisSquared;

The force will be halved at twice the distance.

--Tim

Link

unread,
Jul 21, 1998, 3:00:00 AM7/21/98
to
TSheehan wrote in message
<199807202131...@ladder03.news.aol.com>...

>Don't forget to normalize that vector, otherwise things
>farther away will be _more_ affected.

YES (whups).

- Mike


Amit Patel

unread,
Jul 21, 1998, 3:00:00 AM7/21/98
to
John Mancine <jman...@voyager.net> wrote:
| Right now I am working on explosions in my game and I want to have the the
| explosion 'push' each entity around.
|
| I need to be able to apply a vector force to the current velocity vector of
| each THING that is effected by the 'push' of the explosion.
|
| I haven't had a ton of math.. but I can do this on paper relatively easily.
| Law of sines/cosines etc etc... and it seemed to be pretty easy to throw
| into the code, but I'm a little confused. Do I have to worry about what
| quadrent each angle is in and stuff like that???
| I'm just overall a little lost on how to make the transition from paper to
| code...
| If you can help, I would really appreciate it. Or maybe someone has code or
| a link to a code example?

Hi John,

My recommendation is to avoid using angles or slopes, because they get
complicated -- things like vertical lines (that have infinite slope)
or angles greater than 360 (or less than 0) just make it harder to
work with.

Convert your <angle, force> to a vector that uses (x,y):

f_x = force * cos(angle)
f_y = force * sin(angle)

[Remember that sin/cos in many languages use RADIANS and not DEGREES,
so convert if necessary.]

Once you've started using (x,y) then it becomes easier. You can do
the same thing for x as you do for y, and in most cases you can treat
the two separately -- they don't interfere. I'll use *_i to stand for
both *_x and *_y below, since the formulas are the same for x and y.

From force, you can get acceleration: F = mass * a

a_i = f_i / mass

From acceleration, you can change the velocity:

v_i = v_i + a_i * time_size

From velocity, you can change the position:

p_i = p_i + v_i * time_size

(The time_size is the amount of time your current calculation is
simulating, like 1/60th of a second.)

Another note: the last two formulas are using the "rectangular rule"
of integration. It's well known that the rectangular rule is not very
good. The trapezoidal rule is better, and Simpson's Rule is even
better. Using Simpson's rule you can do far fewer calculations to get
the same quality results, so once you've gotten things working you
might want to investigate using different forms of integration.

- Amit

0 new messages