Programming Gravity

Alexander Horowitz's icon

Hi all,

I have built a platformer game engine (think Mario) in Jitter, but I have no idea how to implement gravity.

The player currently jumps in a linear motion, but this is rather unrealistic. I would like to be able to jump in a parabolic motion.

I have made an example patch; I hope anyone can help!

Max Patch
Copy patch and select New From Clipboard in Max.

Alex

seejayjames's icon

You can use a itable and a sine to get pretty close, the effect seems parabolic enough... if you want to experiment more, [uzi] --> [expr] with the right [scale] objects in there will get you all kinds of function-based data lists. Then just save your most useful ones with [preset] attached to your [itable], to recall whenever you want...maybe some parts of your game should have stronger gravity than others?

Max Patch
Copy patch and select New From Clipboard in Max.

Interested to see the progress! I think there's tons of game potential in Max and Jitter, but haven't seen many out there. Unless you call new video/audio instruments/controllers a kind of "game", which I think is pretty accurate, but maybe not quite what people generally think of as "game-like". I guess you need to have levels and bosses and points... :)

Andrew Benson's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Here's a basic 1D physics thing with gravity, friction, etc.

Alexander Horowitz's icon

Brilliant! This will really give me something to work with.

Just need to get it working with collision detection...

Thanks a lot!

Alexander Horowitz's icon

Just saw Andrew's patch. That might actually be more useful.

However, this there any way with either example for the downwards momentum to continue after the jump? For example, if the character were to jump off a cliff.

Andrew Benson's icon

Just lower the [clip] minimum value if you want it to go below 0. It's there to prevent going out of the range.

Alexander Horowitz's icon

Of course. That's much easier. Since my last post I'd deleted your [clip] object, and was then working out what to replace it with. Ha.

seejayjames's icon

the recursive elements back into the floats are great, and for me were not at all obvious when starting out with this stuff. like a

a = a * 1.05

in code-based syntax, but here it goes back into the right inlets of the operators or floats. without being careful you can get stack overflows, and the order of operations can also be essential, depending on how you set things up.

Full-blown 2D and 3D physics engines would be great, I imagine there are parts to all of these out there, but it definitely makes you learn a lot by putting things together yourself. The [nodes] object is also worth a long look, there's the distance calculations built-in, so you could do all kinds of stuff with friction and gravity...maybe the nodes could be your "bad guys" or objects you collect for points? they wouldn't have to necessarily be visible to be used, you could have your own interface for the interaction if you want, then use the calculations in nodes to test for proximity, collision, etc.

Roman Thilenius's icon
Mathieu Chamagne's icon

my favorite one : box2d (2D rigid body simulation engine)
for Max & PD :
http://charles.bascou.free.fr/box2d/

Mathieu

brendan mccloskey's icon

To do this natively, there is of course [curve~]; simple to vary 'distance', 'height' and 'arc':

Max Patch
Copy patch and select New From Clipboard in Max.

Brendan

grg's icon

Here's another one - gravity now works in outer space ;)

It actually acts as acceleration now, friction is still wrong though for movement in air - should be fine if you set it to zero for a jump and run.

Max Patch
Copy patch and select New From Clipboard in Max.

brendan mccloskey's icon

Can't seem to stay away from this one...

"NOW WITH ADDED BOUNCY-BOUNCY":

Max Patch
Copy patch and select New From Clipboard in Max.

Brendan

seejayjames's icon

n00b that is totally addictive...love it

brendan mccloskey's icon

And now with added addictiv -ity, -ness..........although a Max/Processing combo would be much more extensible.

Max Patch
Copy patch and select New From Clipboard in Max.

Not exactly CallOfDuty, but hey....
Brendan

Dg's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Jitter bounce example.
Try change dims ...