Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / Need help with math... :(

Author
Message
GSX R
21
Years of Service
User Offline
Joined: 19th Jan 2005
Location:
Posted: 27th Jan 2005 06:55
I'm trying to make a code with gravity for a ship.

The problem is, that the ship will have one engine and use rotate sprite to be able to go accelerate in different directions.

What I cant get right is the gravity code for the ship when its going with a sideways speed as well for a upwards speed.

I guess this is like a bullet trajectory, it has a speed and gravity is slowly pulling it down but it will still be moving forward very quickly.

All help is appreciated.
ZtEaLmAx
21
Years of Service
User Offline
Joined: 4th Dec 2004
Location: Sweden
Posted: 29th Jan 2005 05:26
I would like to know that too...


Quote of the week: These humans i like, they are greedy! - Quark (DS9) - [href]www.darkbasicpro.tk[/href]
BlinkOk
22
Years of Service
User Offline
Joined: 22nd Oct 2003
Location:
Posted: 29th Jan 2005 07:57
in my experience gravity is a value that is added to the y value of the object on a per frame basis. this can be implemented if your speed is kept as a slope so you would have an xspeed and a yspeed. for each frame you would add the xspeed and yspeed to the position of the sprite. ie;

assuming the y value increases as the object heads toward the ground then you would add gravity like so;

it is always a good idea to implement friction when your adding gravity otherwise the movement will look too pronounced. you can add friction by multiplying the x/y speed by a value close to but less than one. the higher the number the less friction. eg;

objects always have a maximum velocity so when adding these values you should check to see that the maximum velocity is not exceeded.


hope this helps

P4 2.8Ghz, 2Gb, 128Mb Radeon Pro, Dark Basic PRO
GSX R
21
Years of Service
User Offline
Joined: 19th Jan 2005
Location:
Posted: 30th Jan 2005 06:09
Thank you very much...

Will try this soon, was convinced that I needed some cos and sin calculations to make this happen, but maybe I was to locked to an idea to see the simple solution..
PowerFang
22
Years of Service
User Offline
Joined: 6th Feb 2004
Location: Australia (But currently in the USA)
Posted: 31st Jan 2005 10:19
Just remember gravity is acceleration and acceleration is added together.

So since gravity is 10 m per second, what that means is every 1 second make the MoveY value decrese by 10. hmm lemme show you using numbers.

If you throw a ball up at 50m a second

Height = Current_Height + Acceleration

CurrentAcceleration = CurrentAcceleration - Gravity

1 sec : Height = 0m + (50m + -10m) = 40m
2 sec : Height = 40m + (40m + -10m) = 70m
3 sec : HEight = 70m + (30m + -10m) = 90m
4 sec : Height = 90m + (20m + -10m) = 100m
5 sec : Height = 100m + (10m + -10m) = 100m
6 sec : Height = 100m + (0m + -10m) = 90m
7 sec : Height = 90m + (-10m + -10m) = 70m
8 sec : Hegiht = 70m + (-20m + -10m) = 40m
9 sec : Height = 40m + (-30m + -10m) = 0m

See how gravity remains constant and you just keep adding it to the Y movement of the object.

Hmm that make sense? not really that clear actually
pizzaman
22
Years of Service
User Offline
Joined: 18th Feb 2004
Location: Gateshead, UK
Posted: 31st Jan 2005 21:10 Edited at: 1st Feb 2005 00:25
@ PowerFang

Sorry to say but thats totally wrong. If you want to find out the height of an object, such as ball when gravity is effecting it, you need to use the equations of motion, which are :

v = u + at
s = ut + 0.5 * at^2
v^2 = u^2 + 2as

a = accelerataion [m/s^2]
s = displacement (distance) [m]
t = time [s]
v = final velocity (final speed) [m/s]
u = intial velocity (start speed) [m/s]

Acceleration is gravity, which can be taken to be 9.81 m/s^2 (on Earth), altough alot of people approximate it to 10 m/s^2.

If you throw a ball vertically upward at a velocity of 50 m/s from the ground (and we take acceleration as 10 m/s^2, and also ignore air resistance), then the following happens:

@ 1s : s = 45 m, v = 40 m/s
@ 2s : s = 80 m, v = 30 m/s
@ 3s : s = 105 m, v = 20 m/s
@ 4s : s = 120 m, v = 10 m/s
@ 5s : s = 125 m, v = 0 m/s - This is the heighest point

The ball then falls back down like this

@ 6s : s = 120 m, v = 10 m/s
@ 7s : s = 105 m, v = 20 m/s
@ 8s : s = 80 m, v = 30 m/s
@ 9s : s = 45 m, v = 40 m/s
@ 10s : s = 0 m, v = 0 - Its back at the point where it was thrown

Hypno Toad
21
Years of Service
User Offline
Joined: 25th Nov 2004
Location:
Posted: 3rd Feb 2005 18:03
Did u take physics at A level or something???
sounds pretty complicated, but I guess youre right

You can't slam a revolving door!!
The meaning of life is...42!!
pizzaman
22
Years of Service
User Offline
Joined: 18th Feb 2004
Location: Gateshead, UK
Posted: 3rd Feb 2005 22:50
Yep I've done A level physics

mathkid
21
Years of Service
User Offline
Joined: 1st Feb 2005
Location: Central Massachusetts
Posted: 11th Feb 2005 05:52
sorry, I couldn't help but notice this thread.

Pizzaman's solution is indeed more accurate, but calculus often involves numerical approximations, and so blinkok and powerfang's methods are still feasible. They are useful approximations and they are much easier to program. Also, if the entire world is approximated the same way, it will still seem realistic and coherent.

It can be hard to tell when to use approximations. I'm making an air hockey game that uses exact formulae. The collision involves a lot of analytic geometry and trigonometry, but it's necessary because approximations don't work as well for such a fast-paced game. For your game, though, approximate methods may be fine. You won't know for sure until you test it.

Login to post a reply

Server time is: 2026-06-11 17:32:21
Your offset time is: 2026-06-11 17:32:21