Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


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.

  • You cannot reply to this topic
4 replies to this topic

#1 Fl00Fy   Members   -  Reputation: 188

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. 



Sponsor:

#2 Paradigm Shifter   Crossbones+   -  Reputation: 5431

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

#3 Nercury   Crossbones+   -  Reputation: 774

Like
2Likes
Like

Posted 19 April 2013 - 01:25 PM

My article may help to get started with vectors.



#4 BeerNutts   Crossbones+   -  Reputation: 2998

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)

#5 Fl00Fy   Members   -  Reputation: 188

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