Forums > MaxMSP

Programming Gravity

August 2, 2011 | 9:46 pm

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. –

August 2, 2011 | 11:07 pm

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. –

August 2, 2011 | 11:07 pm

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. –

August 2, 2011 | 11:22 pm

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

– Pasted Max Patch, click to expand. –

August 2, 2011 | 11:22 pm

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

– Pasted Max Patch, click to expand. –

August 2, 2011 | 11:29 pm

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

Just need to get it working with collision detection…

Thanks a lot!


August 2, 2011 | 11:29 pm

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

Just need to get it working with collision detection…

Thanks a lot!


August 2, 2011 | 11:37 pm

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.


August 2, 2011 | 11:37 pm

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.


August 2, 2011 | 11:45 pm

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


August 2, 2011 | 11:45 pm

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


August 2, 2011 | 11:52 pm

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.


August 2, 2011 | 11:52 pm

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.


August 3, 2011 | 12:37 am

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.


August 3, 2011 | 12:37 am

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.


August 3, 2011 | 3:38 am

pmpd


August 3, 2011 | 3:38 am

pmpd


August 3, 2011 | 8:37 am

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

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

Mathieu


August 3, 2011 | 8:37 am

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

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

Mathieu


August 3, 2011 | 10:40 am

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

– Pasted Max Patch, click to expand. –

Brendan


August 3, 2011 | 10:40 am

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

– Pasted Max Patch, click to expand. –

Brendan



grg
August 5, 2011 | 11:45 am

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;



grg
August 5, 2011 | 11:45 am

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;


August 5, 2011 | 3:00 pm

Can’t seem to stay away from this one…

"NOW WITH ADDED BOUNCY-BOUNCY":

– Pasted Max Patch, click to expand. –

Brendan


August 5, 2011 | 3:00 pm

Can’t seem to stay away from this one…

"NOW WITH ADDED BOUNCY-BOUNCY":

– Pasted Max Patch, click to expand. –

Brendan


August 6, 2011 | 2:06 am

n00b that is totally addictive…love it


August 6, 2011 | 2:06 am

n00b that is totally addictive…love it


August 6, 2011 | 10:13 am

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


August 6, 2011 | 10:13 am

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


August 6, 2011 | 5:31 pm

Jitter bounce example.
Try change dims …

– Pasted Max Patch, click to expand. –

August 6, 2011 | 5:31 pm

Jitter bounce example.
Try change dims …

– Pasted Max Patch, click to expand. –

Viewing 31 posts - 1 through 31 (of 31 total)