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

gravity with a vector?

Started by thedodgeruk Jan 18, 2011 at 12:43 PM 7 replies 6.7k views
Original Post
thedodgeruk
thedodgeruk
i have a particle moving along a vector, but want gravity to effect it

can some one point me toward how this is done , im sure i have seen it some were, can any one point out a good tutrail for tis plaese
terry_burns85
terry_burns85
Given a 3d vector of X, Y and Z. Manipulating the Y value each frame should give you your desired result, play around with the value you subract from the Y to find what best suits.
---Terence Burns---
Ezbez
Ezbez
Gravity applies an acceleration. This means that it directly modifies the velocity, not the position. The simplest way to model this is as follows:

position (a vector)
velocity (a vector)
gravity (a vector)

each frame:
deltaTime = time elapsed since the last frame
velocity += gravity * deltaTime
position += velocity * deltaTime


The length and direction of the gravity vector then determines how strong and in which direction gravity is. For Earth, the gravity vector would have magnitude of 9.8 m/s/s or 32 ft/s/s.
c_olin
c_olin
A force can be represented by a vector indicating the direction of the force and the magnitude. The Earth's gravity near the surface is 9.8 m/s^s. This means that if you drop an object it will gain 9.8 m/s every second (ignoring all opposing forces).

To apply gravity to your particles, add the gravity force to the velocity of the particle when you update.

Let G = Vector3(0, -9.8, 0)

If you update your particles 30 times a second then for each frame add G / 30 to your particle's velocity.
Sappharos
Sappharos

Gravity applies an acceleration. This means that it directly modifies the velocity, not the position. The simplest way to model this is as follows:

position (a vector)
velocity (a vector)
gravity (a vector)

each frame:
deltaTime = time elapsed since the last frame
velocity += gravity * deltaTime
position += velocity * deltaTime


The length and direction of the gravity vector then determines how strong and in which direction gravity is. For Earth, the gravity vector would have magnitude of 9.8 m/s/s or 32 ft/s/s.


I've never seen it explained more clearly. But a quick question, thedodgeruk, is your gravity in a constant direction, or is it for example a top-down space shooter in which gravity is affected by nearby stars/planets?
Zakwayda
Zakwayda

Given a 3d vector of X, Y and Z. Manipulating the Y value each frame should give you your desired result, play around with the value you subract from the Y to find what best suits.

Note that this assumes the 'y' axis is up; however, this is not always the case (the 'z-up' convention is also fairly common).
thedodgeruk
thedodgeruk

[quote name='Ezbez' timestamp='1295361391' post='4760713']
Gravity applies an acceleration. This means that it directly modifies the velocity, not the position. The simplest way to model this is as follows:

position (a vector)
velocity (a vector)
gravity (a vector)

each frame:
deltaTime = time elapsed since the last frame
velocity += gravity * deltaTime
position += velocity * deltaTime


The length and direction of the gravity vector then determines how strong and in which direction gravity is. For Earth, the gravity vector would have magnitude of 9.8 m/s/s or 32 ft/s/s.


I've never seen it explained more clearly. But a quick question, thedodgeruk, is your gravity in a constant direction, or is it for example a top-down space shooter in which gravity is affected by nearby stars/planets?
[/quote]



all depends on the particle....
for explosion i want gravity
smoke i want , a kind of invert gravity

thedodgeruk
thedodgeruk

Gravity applies an acceleration. This means that it directly modifies the velocity, not the position. The simplest way to model this is as follows:

position (a vector)
velocity (a vector)
gravity (a vector)

each frame:
deltaTime = time elapsed since the last frame
velocity += gravity * deltaTime
position += velocity * deltaTime


The length and direction of the gravity vector then determines how strong and in which direction gravity is. For Earth, the gravity vector would have magnitude of 9.8 m/s/s or 32 ft/s/s.


woudld this give a smooth curve to the particle . and do i have to normalise the vectors , or am i being stupid .

would it be something like


vect3 position = get start position of particle;
vec3 directionVector = direction of movement

vect3 = gravity

loop
{
deltaTime = time elapsed since the last frame

directionVector += gravity * deltaTime
position += directionVector * deltaTime

setParticle to position;
}

Topic Locked

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

Sign in to reply to this topic.