# Thread: I need help with a gravity simulator!

1. Member Join Date
Dec 2011
Posts
3
Rep Power
0

## I need help with a gravity simulator!

Hey Guys,

I'm trying to write a game-like program which simulates an object falling to the ground, while I can do all the physics and maths behind this I really really
suck at java at this level :( if any of you guys could help me out with this I'd be forever grateful ^_^

Thanks,

Karly Xx  Reply With Quote

2. ## Re: I need help with a gravity simulator!

Per unit of time the velocity v increases with a value a (due to gravity) so at a time t+1 the velocity becomes v+a; the distance to the ground decreases by a distancve v, so the distance at t+1 becomes d-v. Repeat until d <= 0 and start your simulation at a height d0 and an initial velocity v0

kind regards,

Jos  Reply With Quote

3. Member Join Date
Dec 2011
Posts
3
Rep Power
0

## Re: I need help with a gravity simulator!

That's cool I just have no idea how to code that :( are there any examples of such a code here or if not do you know where I can find code examples?  Reply With Quote

4. ## Re: I need help with a gravity simulator! Originally Posted by Karly_Kute_X That's cool I just have no idea how to code that :( are there any examples of such a code here or if not do you know where I can find code examples?
There is not much coding involved; as a bare bones minimum your simulation looks like this:

Java Code:
```double d= d0; // initial height
double v= v0; // initial velocity

while (d > 0) { // while no impact yet
}```
kind regards,

Jos  Reply With Quote

5. Member Join Date
Dec 2011
Posts
3
Rep Power
0

## Re: I need help with a gravity simulator!

Ahh that makes more sense - although I need to represent the initial and final positions as vectors - I understand I need to use arrays to do this - I just don't know how to make the program do this, also I need to allow the user to alter the mass of whats being dropped and the mass of the planet :(:(

Grrr confuzzled! :\

K x  Reply With Quote

6. ## Re: I need help with a gravity simulator!

Vectors only make sense in the calculations if there is a horizontal component in the speed (vx, vy), otherwise the first component of these vectors will always be zero. The force applied to the falling body only infuences the vertical speed component. The mass of the planet only influences component 'a' in the calculations (i.e. the gravity factor)

kind regards,

Jos  Reply With Quote

game, gravity, physics 