Programming Gravity

Aug 2, 2011 at 9:46pm

Programming Gravity

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!

Alex

– Pasted Max Patch, click to expand. –
#58323
Aug 2, 2011 at 11:07pm

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?

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… :)

– Pasted Max Patch, click to expand. –
#209562
Aug 2, 2011 at 11:07pm

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?

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… :)

– Pasted Max Patch, click to expand. –
#209565
Aug 2, 2011 at 11:22pm

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

– Pasted Max Patch, click to expand. –
#209563
Aug 2, 2011 at 11:22pm

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

– Pasted Max Patch, click to expand. –
#209567
Aug 2, 2011 at 11:29pm

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

Just need to get it working with collision detection…

Thanks a lot!

#209564
Aug 2, 2011 at 11:29pm

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

Just need to get it working with collision detection…

Thanks a lot!

#209569
Aug 2, 2011 at 11:37pm

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.

#209566
Aug 2, 2011 at 11:37pm

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.

#209570
Aug 2, 2011 at 11:45pm

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

#209568
Aug 2, 2011 at 11:45pm

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

#209571
Aug 2, 2011 at 11:52pm

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.

#209572
Aug 2, 2011 at 11:52pm

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.

#209587
Aug 3, 2011 at 12:37am

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.

#209573
Aug 3, 2011 at 12:37am

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.

#209588
Aug 3, 2011 at 3:38am

pmpd

#209574
Aug 3, 2011 at 3:38am

pmpd

#209589
Aug 3, 2011 at 8:37am

my favorite one : box2d (2D rigid body simulation engine)
for Max & PD :

http://charles.bascou.free.fr/box2d/

Mathieu

#209575
Aug 3, 2011 at 8:37am

my favorite one : box2d (2D rigid body simulation engine)
for Max & PD :

http://charles.bascou.free.fr/box2d/

Mathieu

#209590
Aug 3, 2011 at 10:40am

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

– Pasted Max Patch, click to expand. –

Brendan

#209576
Aug 3, 2011 at 10:40am

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

– Pasted Max Patch, click to expand. –

Brendan

#209591
Aug 5, 2011 at 11:45am

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 v2;
#N vpatcher 651 88 2037 896;
#P user multiSlider 724 564 144 155 0. 100. 1 3193 15 0 0 2 0 0 0;
#M frgb 0 0 0;
#M brgb 255 255 255;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 37 52 91;
#M rgb5 74 105 182;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P user multiSlider 694 564 29 155 0. 100. 1 2681 15 0 0 2 0 0 0;
#M frgb 0 0 0;
#M brgb 255 255 255;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 37 52 91;
#M rgb5 74 105 182;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P window setfont “Sans Serif” 9.;
#P flonum 400 476 94 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P toggle 435 178 15 0;
#P window linecount 1;
#P newex 435 153 60 196617 loadbang;
#P comment 160 211 156 196617 jump strength (initial accel);
#P newex 572 481 33 196617 + 0.;
#P newex 660 507 69 196617 clip 0. 100.;
#P comment 567 329 47 196617 friction;
#P newex 516 359 33 196617 + 1.;
#P flonum 516 328 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 351 178 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 332 208 29 196617 f 15;
#P newex 435 384 34 196617 / 1.1;
#P comment 514 295 156 196617 gravity (constant accel);
#P flonum 458 294 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 435 321 33 196617 – 0.4;
#P newex 435 200 58 196617 metro 30;
#P comment 629 479 260 196617 position (new pos = old pos + delta);
#P comment 279 478 114 196617 delta (velocity);
#P newex 435 260 33 196617 f;
#P user uslider 660 563 20 140 100 1 0 0;
#P newex 332 148 43 196617 sel 32;
#P newex 332 118 60 196617 key;
#P connect 0 0 1 0;
#P connect 1 0 11 0;
#P connect 12 0 11 1;
#P connect 10 0 21 0;
#P connect 19 0 20 0;
#P connect 20 0 6 0;
#P connect 6 0 3 0;
#P connect 11 0 3 0;
#P connect 3 0 7 0;
#P connect 7 0 10 0;
#P fasten 10 0 3 1 440 427 413 427 413 233 463 233;
#P connect 8 0 7 1;
#P connect 14 0 10 1;
#P connect 13 0 14 0;
#P connect 10 0 17 0;
#P connect 16 0 17 1;
#P connect 17 0 16 0;
#P connect 16 0 2 0;
#P connect 16 0 22 0;
#P connect 16 0 23 0;
#P pop;

#209577
Aug 5, 2011 at 11:45am

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 v2;
#N vpatcher 651 88 2037 896;
#P user multiSlider 724 564 144 155 0. 100. 1 3193 15 0 0 2 0 0 0;
#M frgb 0 0 0;
#M brgb 255 255 255;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 37 52 91;
#M rgb5 74 105 182;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P user multiSlider 694 564 29 155 0. 100. 1 2681 15 0 0 2 0 0 0;
#M frgb 0 0 0;
#M brgb 255 255 255;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 37 52 91;
#M rgb5 74 105 182;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P window setfont “Sans Serif” 9.;
#P flonum 400 476 94 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P toggle 435 178 15 0;
#P window linecount 1;
#P newex 435 153 60 196617 loadbang;
#P comment 160 211 156 196617 jump strength (initial accel);
#P newex 572 481 33 196617 + 0.;
#P newex 660 507 69 196617 clip 0. 100.;
#P comment 567 329 47 196617 friction;
#P newex 516 359 33 196617 + 1.;
#P flonum 516 328 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 351 178 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 332 208 29 196617 f 15;
#P newex 435 384 34 196617 / 1.1;
#P comment 514 295 156 196617 gravity (constant accel);
#P flonum 458 294 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 435 321 33 196617 – 0.4;
#P newex 435 200 58 196617 metro 30;
#P comment 629 479 260 196617 position (new pos = old pos + delta);
#P comment 279 478 114 196617 delta (velocity);
#P newex 435 260 33 196617 f;
#P user uslider 660 563 20 140 100 1 0 0;
#P newex 332 148 43 196617 sel 32;
#P newex 332 118 60 196617 key;
#P connect 0 0 1 0;
#P connect 1 0 11 0;
#P connect 12 0 11 1;
#P connect 10 0 21 0;
#P connect 19 0 20 0;
#P connect 20 0 6 0;
#P connect 6 0 3 0;
#P connect 11 0 3 0;
#P connect 3 0 7 0;
#P connect 7 0 10 0;
#P fasten 10 0 3 1 440 427 413 427 413 233 463 233;
#P connect 8 0 7 1;
#P connect 14 0 10 1;
#P connect 13 0 14 0;
#P connect 10 0 17 0;
#P connect 16 0 17 1;
#P connect 17 0 16 0;
#P connect 16 0 2 0;
#P connect 16 0 22 0;
#P connect 16 0 23 0;
#P pop;

#209592
Aug 5, 2011 at 3:00pm

Can’t seem to stay away from this one…

“NOW WITH ADDED BOUNCY-BOUNCY”:

– Pasted Max Patch, click to expand. –

Brendan

#209578
Aug 5, 2011 at 3:00pm

Can’t seem to stay away from this one…

“NOW WITH ADDED BOUNCY-BOUNCY”:

– Pasted Max Patch, click to expand. –

Brendan

#209593
Aug 6, 2011 at 2:06am

n00b that is totally addictive…love it

#209579
Aug 6, 2011 at 2:06am

n00b that is totally addictive…love it

#209594
Aug 6, 2011 at 10:13am

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

– Pasted Max Patch, click to expand. –

Not exactly CallOfDuty, but hey….
Brendan

#209580
Aug 6, 2011 at 10:13am

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

– Pasted Max Patch, click to expand. –

Not exactly CallOfDuty, but hey….
Brendan

#209595
Aug 6, 2011 at 5:31pm

Jitter bounce example.
Try change dims …

– Pasted Max Patch, click to expand. –
#209581
Aug 6, 2011 at 5:31pm

Jitter bounce example.
Try change dims …

– Pasted Max Patch, click to expand. –
#209596

You must be logged in to reply to this topic.