Main Menu

Implementing gravity

Started by darkx, June 28, 2012, 03:48:27 AM

Previous topic - Next topic

darkx

So far I've only taken physics 20 so I only know the basic and I've kind of forgotten some of the stuff. For implementing gravity within a game would like a character jumping you would just get the velocity every second with timer() and do something like y=y+velocity every second? ???



BlinkOk

its a separate equation i think something like

y=y-(gravity*elapsed)

gravity = gravity per second
elapsed = elapsed time since you last applied gravity
normally i just make it an arbitrary value and see how it looks. i generally apply this after everything else like friction and external forces
adding or subtraction depends on the co-ordinate system. cant remember how it's implemented in PB

kevin


darkx

#3
Thanks for the response guys I'm going to experiment over these they look very interesting especially the ray casting I didn't even know what it was about until I googled it up today. It looks very useful for map collision, LoS, Projectiles, Light, etc.

[Edit]

After looking at the examples physics tutorial looks like I way doing really unneeded things and making life overly complicated like using physics formulas trying to use time and stuff

LemonWizard

Here's a pro-tip my friend.
If you initialize alot of your gravity based variables as floating points playbasic can actually calculate changes up to say .. the hundredth or thousandth decimal point (and more?)

Well that might be a bit much anyhow seeing as when I say thousandth I'm thinking 0.001.
But yeah you get the idea.
One pixel in your drawing coordinates is equivalent to 1.0 (whole number)
SO basically.. if you want some variation I'd add a floating point to your gravity value. Or leave your gravity alone and change your actual fall speed intead.
I'd set a vector for your gravity so you can do cool things like change the direction of gravity to X angle.

That takes a bit more calculation though and i've never tried it myself with playbasic but I've done stuff like that in game maker (derp I know right?)