UnderwareDESIGN

PlayBASIC => Game Design => Topic started by: darkx on June 28, 2012, 03:48:27 AM

Title: Implementing gravity
Post by: darkx on June 28, 2012, 03:48:27 AM
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? ???


Title: Re: Implementing gravity
Post by: BlinkOk on June 28, 2012, 06:43:25 AM
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
Title: Re: Implementing gravity
Post by: kevin on June 28, 2012, 03:19:50 PM
Platformer Pixel Collisions Via Ray Casting (http://www.underwaredesign.com/forums/index.php?topic=3163.0)

Very basic lunar lander (http://www.underwaredesign.com/forums/index.php?topic=3076.0)

Title: Re: Implementing gravity
Post by: darkx on June 28, 2012, 08:15:12 PM
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
Title: Re: Implementing gravity
Post by: LemonWizard on August 22, 2012, 12:22:38 AM
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?)