Custom movement boxes with gravity

0 favourites
  • 3 posts
From the Asset Store
Run and Jump in 3 Dimensions! Take your platformer to the next level!
  • I've got some simple mechanics that I thought would be doable with custom movement, but I've got no clue how to use it. Here's what I want the boxes to do:

    I've got this to work with a platform behavior on each box & some events locking their movement axis, & even got it working with raycast collisions in chipmunk. But I'd like to do it with custom movement just out of curiosity since I've never used it before.

    Here's how far I got <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy"> ... Boxes.capx

  • The customMovement behavior doesn't really add much to be helpful for that. maybe the "stepping mode" where you can check for collisions in the in between positions with the "on step" trigger.

    Pushing out once colliding isn't the best here. It would be better check if the way is clear before moving.

    And actually I would go for doing the whole thing with events.

    I'd put everything I wanted to collide with in a family and call that solid then the simplest example would be this:

    [negated] sprite: overlaps solid at offset (1,0)

    sprite: set x to self.x+1

    You could then extend it with a speed instance variable to make the acceleration and finer motion:

    [negated] sprite: overlaps solid at offset (self.speed*dt,0)

    sprite: set x to self.x+self.speed*dt

    sprite: add 1500*dt to speed


    sprite: set speed to 0

    When hitting a solid it will look to stop short sometimes and close the gap. This can be improved by using a loop to check each step in between. for that add another instance variable called "delta". Another benefit is this keeps the objects on pixel coordinates while staying framerate independent. This adds consistency to the collisions so they always stop the same distance away.

    every tick

    sprite: add 1500*dt to speed

    sprite: add self.speed*dt to delta

    repeat times

    ---[negated] sprite: overlaps solid at offset (1,0)

    --- > sprite: set x to self.x+1

    --- > sprite: subtract 1 from delta


    --- > stop loop

    --- > sprite: set delta to 0

    --- > sprite: set speed to 0

    Now you could instead use the custom movement behavior instead by setting the stepping mode property and using the on step trigger. The only issue is "on step" is triggered after the object moves so you'll have to back it up or push out. That can go wrong if it pushes out into another object, which can easily happen with objects with floating point coordinates while being close to each other.


    Here's an example: ... _move.capx

    The events are generic for any angle and I shrank the collision polygon a bit.

    One more thing that could be done with this is simultaneous movement of the blocks. Right now their motion is handled on by one, but you also could let each move a pixel, then repeat for all of their deltas are below 1. ... neous.capx

    Further tweaks would probably be some rounding in some spots to keep things with integer values, but I'm not sure if it's needed.


    had a typo in limiting the speed. used max when it should have been min.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • This is great, exactly the kind of elegant solution I was hoping to do, thanks!

    The simultaneous example is very helpful & not something i would have thought of. I've always been unsure about where to use while loops. I did a stress test with both your examples (although I won't be using more than 10 or 20 boxes at a time) & interestingly the simultanous movement had the best performance. 300+ boxes 60fps, i think that should do it <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy"> ... tress.capx ... tress.capx

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