Collision, Gravity & Jumping

This forum is currently in read-only mode.
From the Asset Store
Particles support animations, collisions, effects and etc.
  • Hello everybody.

    I've been looking around the forum for a few days, while battling with events, and havent yet found a solution. So now i'm turning to you in desperation, and hoping not to bother ya'll too much.

    The deal is this: i'm working on a platformer, but instead of using the platform behaviou, (since it didnt allow me to worki the way i needed to) i decided to accomplish it via events. some might call this tedious, redundant, or needless, but i personally find it more effective, and to each their own.

    So far, i have gotten the controls and commands correctly, some of the gravity, and some of the jumping. but i cannot get collision to work correctly

    i would like to know First of all, how would you go about setting up a collision system via events?

       for example, my Gravity is a constant force of 8px in 90� [downwards] every 16milisecond. (and mostly 16ms is my basic unit of time for measurement) - unless there is collision with ground-type object.

    however the object which is falling, ends up stuck somewhat IN the ground, which i guess means that the collision is being detected AFTER it has sunk into the ground.

    i tried lowering the amount of downward pixels and time intervals proportionally, but this nevertheless made things just fall slower [though sometimes they did not sink]

    so, how would you, with events:

            * set up Gravity

            * Set up Collition

            * set up Jumping

    thanks to anybody who reads this, if i wasnt clear please just ask

  • What about the platform behavior doesn't do what you want it to?

    As for custom collisions, put everything you want to push out of in a family, use the custom movement behavior on the player, and the push out of object action, with normal (slide) selected, and have that family selected as the object to push out of when the player overlaps the family.

    You can probably do the gravity and jumping with custom movement too, or you could use normal events (set position and have x and y values that you add/subtract from for speed).

  • Try using the box 2d physics. It's much more fun:

    scirra.com/forum/topic43788_post273940.html

    <img src="smileys/smiley3.gif" border="0" align="middle" />

  • Thanks for the responses.

    I've been trying to work it out and i thinking i got something.

    Urled:

    i checked the link but wasnt completely able to make out what you were referring to. i did check the stuff out, so thanks anyway.s

    Arima:

    thanks for your tip. it made perfect sense, however for some reason i couldnt get it to function correctly. however inspired by your tip i came up with a solution. that resolved collision and gravity

    basically what i did was this:

    :: C O L L I S I O N ::

    -------------------------

    + System: Object.Bottom - Ground.Top Greater than 0

         -> System: Set global variable 'collision' to 0

    :: G R A V I T Y ::

    -------------------------

    + System: global('collision') Equal to 0

         -> System: Start loop "gravity" and run 1024 times

         + System: On loop "gravity"

         + System: Object.Bottom - Ground.Top Greater or equal 0

              -> System: Set global variable 'collision' to 1

         + System: global('collision') Equal to 0

         + System: [negated] Object (Pick) and Ground (Pick) are overlapping

              -> Object: Set Y to Object.Y + (1 * TimeDelta)

    i'd like to upload an example, but i'm not sure how.

    this seems to work pixel perfect, and at great speeds.

    but i must confess i'm not quite sure of how it works,

    i came up with it late at night after fiddling a lot,

    and without a rested mind, so i might need cleaning up,

    and perhaps could be optimized.

    somehow lowering or rising the number of times the loop is repeated affects the gravity speed proportionally, but i'm not sure of what the pixel per frame or millisecond is. but i'd like to find out in order to control the rate.

    also, i'm not sure of what the exact value of timedelta is supposed to be, is each time delta something like 16.666~~~ milliseconds?

  • :: G R A V I T Y ::

    -------------------------

    <font color=orange>+ System: global('collision') Equal to 0</font>

         -> System: Start loop "gravity" and run 1024 times

         + System: On loop "gravity"

         + System: Object.Bottom - Ground.Top Greater or equal 0

              -> System: Set global variable 'collision' to 1

         <font color=orange>+ System: global('collision') Equal to 0</font>

         + System: [negated] Object (Pick) and Ground (Pick) are overlapping

              -> Object: Set Y to Object.Y + (1 * TimeDelta)

    The second one is a redundant condition, you already compared 'collision'. In this scenario (without knowing the rest of your events) Object.Y will grow by 1 pixel per second (1 * TimeDelta) as long as 'collision' is 0.

    also, i'm not sure of what the exact value of timedelta is supposed to be, is each time delta something like 16.666~~~ milliseconds?

    There is no exact value. Timedelta is a value expressing the time passed since the last tick (may also call it frame) in milliseconds. This time varies depending on how many events needed to be executed in the last tick, how many other processes took time (e.g. some access to the graphic card by a browser), etc.

    So this value will be slightly different on each tick. But you can rely on the sum of TimeDelta. If your game runs with 60 fps, then adding TimeDelta 60 times will result to 1. And 1/TimeDelta will give you the actual framerate - but only valid for that time of moment.

  • The second one is a redundant condition, you already compared 'collision'. In this scenario (without knowing the rest of your events) Object.Y will grow by 1 pixel per second (1 * TimeDelta) as long as 'collision' is 0. delta something like 16.666~~~ milliseconds?

    i thought so too! but my reasoning was to have one check [outside the loop] which triggered the loop, and one INSIDE the loop to keep checking in every turn whilst the loop ran. otherwise it would assume it to be 0 from before the loop started.

    however, i tried toggling it off, and the object stopped one pixel late, sinking into the ground. when i turned it back on it worked fine.

    also, referring to time delta, so if time delta is the time [in ms] between each frame. if it ran at 60FPS would it be safe to say that TimeDelta = 1 second / FPS. or 1/60 second? so as long as it were 60fps it would be 0.016~s. ?? <img src="smileys/smiley17.gif" border="0" align="middle">

    i now uploaded the example.

    Time Delta Gravity

  • i thought so too! but my reasoning was to have one check [outside the loop] which triggered the loop, and one INSIDE the loop to keep checking in every turn whilst the loop ran. otherwise it would assume it to be 0 from before the loop started.

    Ah, yes, that's right. It was just a confusing set of events, but it needs to check again, that's correct. Sorry about that.

    also, referring to time delta, so if time delta is the time [in ms] between each frame. if it ran at 60FPS would it be safe to say that TimeDelta = 1 second / FPS. or 1/60 second? so as long as it were 60fps it would be 0.016~s. ?? <img src="smileys/smiley17.gif" border="0" align="middle">

    No :)

    The framerate is just an average value. You might get 60 frames per second in the end, but there is no guarantee, that every tick lasts the same amount of time. It rather is something like

    f1: 15ms

    f2: 18ms

    f3: 13ms

    f4: 11ms

    f5: 16ms

    etc.

    i now uploaded the example.

    Time Delta Gravity

    Couldn't download it. (dropbox error 403)

  • The framerate is just an average value. You might get 60 frames per second in the end, but there is no guarantee, that every tick lasts the same amount of time.

    i see, i guess that makes sense, it depends on how long it would take to compute before the next draw.

    does it also mean that i have no way of setting a fixed rate of pixel per second with that method? or do you have any idea of how that would work? <img src="smileys/smiley4.gif" border="0" align="middle" />

    Couldn't download it. (dropbox error 403)

    hmm, strange. i uploaded it to mediafire if you care to check it out.

    mediafire.com

  • The deal is this: i'm working on a platformer, but instead of using the platform behaviou, (since it didnt allow me to worki the way i needed to)

    I am quite interested in what it is in particular that you are trying to achieve that the platform behaviour would impede.

  • superpowerjoe

    The dropbox download error is because you provided the private url instead of the public one.

  • superpowerjoe

    The dropbox download error is because you provided the private url instead of the public one.

    Thanks for the tip! I thought it'd be something like that, but dont know how to get the public url though, :S

    I am quite interested in what it is in particular that you are trying to achieve that the platform behaviour would impede.

    I know it sounds pretentious, but i cant really put it into concise words.

    But for example i've seen that sustained jump and double [or multiple] jumps are a bit of an issue. And also i'd like to have varying jump and gravity speeds, as well as a non arched jump. Sorry if i'm not clear enough, but that's how i manage to describe some of it.

    I do however think the platform behaviour is a great implementation. And an ideal tool for someone to just put something together without having to break open their skulls.

    But i'm sorta the stubborn person that likes to invent the wheel and know the internal workings of it, while being able to say that it was crafted to some extent by me with my personal flavour. Dont get me wrong i'm not saying that the platform behaviour doesnt work or any of the sort. <img src="smileys/smiley17.gif" border="0" align="middle" />

  • Thanks for the tip! I thought it'd be something like that, but dont know how to get the public url though, :S

    Place files in the Public folder and just press right mouse on file and select 'Copy Public link' (I may be paraphrasing slightly as I can't remember the exact wording off the top of my head).

  • Place files in the Public folder and just press right mouse on file and select 'Copy Public link' (I may be paraphrasing slightly as I can't remember the exact wording off the top of my head).

    THANKS!

    it seems i got it working, this should be it!

    drop box link

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Sorry for the delay.

    does it also mean that i have no way of setting a fixed rate of pixel per second with that method? or do you have any idea of how that would work? <img src="smileys/smiley4.gif" border="0" align="middle"> It might be mixed up now. When using 1 * Timedelta, you have a fixed rate of 1 pixel per second. No matter the frame length or frame rate, overall you will have exactly that rate.

    The problem is the loop though. It will be run 1024 times per call, so if the framerate is high the resolution is much higher than with a low framerate.

    I have made a cap that uses a much more efficient way. Have a look at it and see if you can use it in some way:

    http://www.mediafire.com/?eq84dhm84w4sowv

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)