• Create Account

Banner advertising on our site currently available from just \$5!

# Gravity's affect on velocity implemented with speed and direction.

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

4 replies to this topic

### #1Fl00Fy  Members   -  Reputation: 198

Like
0Likes
Like

Posted 19 April 2013 - 12:37 PM

Sorry if the title's a bit confusing, had trouble trying to summarise the problem in a good way.

Anywho, it seems I may have coded myself into a bit of pickle. I'm trying to create a game which includes gravity and some stuff which is affected by it... I decided, when I started the project, that I would describe each objects velocity with two scalars: speed and direction (in radians, right being 0). It's worked out well so far, until I tried to implement gravity.

The problem is, I can't figure out how to account for gravity by giving the object a downward force. If this just happens to be a bad way to implement velocity, I would be alright with having to change the code to use a different method; but if there is a viable solution for this, I'd love to hear it.

Help of any kind would be appreciated.

### #2Paradigm Shifter  Crossbones+   -  Reputation: 5571

Like
1Likes
Like

Posted 19 April 2013 - 01:21 PM

Use a 2d vector for your velocity instead. You can convert your direction and speed into a vector easily using trig.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

### #3Nercury  Crossbones+   -  Reputation: 808

Like
2Likes
Like

Posted 19 April 2013 - 01:25 PM

My article may help to get started with vectors.

### #4BeerNutts  Crossbones+   -  Reputation: 3456

Like
1Likes
Like

Posted 19 April 2013 - 01:57 PM

You can always use "pseudo" gravity as well, just by adding to the Y-position by an increasing gravity value:
void PhysicalObject::Update(double deltaTime)
{
if (NotOnGround) {
YPosition += GravityVelocity;
GravityVelocity += GravityAcceleration*deltaTime;
}
else {
GravityVelocity = 0;
}
}


My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

### #5Fl00Fy  Members   -  Reputation: 198

Like
0Likes
Like

Posted 19 April 2013 - 02:03 PM

Thanks for all the advice. I'll probably end up adding the vector implementation. It's about time I start using them to be honest. And the article was a great help, thanks.

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS