Programming Gravity

    Aug 02 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!

    • Aug 02 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... :)
    • Aug 02 2011 | 11:22 pm
      Here's a basic 1D physics thing with gravity, friction, etc.
    • Aug 02 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!
    • Aug 02 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.
    • Aug 02 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.
    • Aug 02 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.
    • Aug 03 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.
    • Aug 03 2011 | 3:38 am
    • Aug 03 2011 | 8:37 am
      my favorite one : box2d (2D rigid body simulation engine) for Max & PD :
    • Aug 03 2011 | 10:40 am
      To do this natively, there is of course [curve~]; simple to vary 'distance', 'height' and 'arc':
    • Aug 05 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.
    • Aug 05 2011 | 3:00 pm
      Can't seem to stay away from this one...
    • Aug 06 2011 | 2:06 am
      n00b that is totally it
    • Aug 06 2011 | 10:13 am
      And now with added addictiv -ity, -ness..........although a Max/Processing combo would be much more extensible.
      Not exactly CallOfDuty, but hey.... Brendan
    • Aug 06 2011 | 5:31 pm
      Jitter bounce example. Try change dims ...