[BEHAVIOR] Sonic Physics

1 favourites
From the Asset Store
Hybrid Sonic Branding Kit is a business identity & motion graphics sound effects library.
  • The Sonic Physics behaviour is a heavily adapted version of the Platform behaviour that can handle slopes and curves in the same way as the classic Sonic the Hedgehog games. The behaviour is mostly accurate to the physics of the games and is primarily targeted towards Sonic fangames, but the behaviour has specifically been made so that unneeded components can be disabled in some way, for use in other games.

    The goal of the behaviour is to be a simple to use as the Platform behaviour itself, aside from some obviously more complicated parts, so the behaviour works almost identically, handling Solids and JumpThrus as you would expect.

    The Sonic Physics Guide was referenced heavily in the development of this behaviour.

    At some stage I intend to work on a template containing supplementary events that didn't fit with the behaviour, as well as things you'd expect to find in a Sonic game, as a base for fangames and a better example of how to use the behaviour.

    Notable Features:

    • Snaps to angled surfaces, as long as speed is above a specified threshold
    • Slopes will affect movement speed and jump angle
    • Modified variable jumping to have a maximum and minimum jump rather than a sustain time (more accurate to old Sonic games)
    • Added variations on basic acceleration, deceleration etc parameters for when in the air or rolling
    • "Compare Speed" condition offers choice between X component, Y component, or both
    • Rolling, which works under the same conditions as it does in the Sonic games. On by default but easily disabled if it's undesirable.
    • More to come, hopefully!

    DOWNLOAD LINK

    EXAMPLE

    EXAMPLE CAPX

    Actions added/modified:

    • Actions corresponding to properties. In order to not clog up the action select window, selecting a property with multiple versions (like acceleration) will offer a combobox asking which variation you'd like to set.
    • Simulate control: Roll
    • Trigger roll/unroll. Overrides the initial conditions for rolling (ie, this isn't the same as "Simulate control: Roll") but triggering a roll is still subject to unroll conditions (ie low speed) and vice-versa.
    • Removed "Set Jump Sustain" as I've changed how the variable jumping works.

    Conditions added/modified:

    • As mentioned above, the "Compare Speed" condition now has an extra combobox to specify whether you'd like to compare X vector, Y vector, or both. Both is the default, which functions as the Platform behaviour's "Compare Speed". Equivalent to comparing Object.SonicPhysics.VectorX/Y.

    Expressions added/modified:

    • "SurfaceAngle": The angle of the surface the player is on. Returns 0 if not on an object.
    • See list of properties below. Most (or all) of those have a corresponding expression to get their value at runtime.

    Properties added/modified:

    • "Soft Max Speed": Max Speed has been separated into two components. This one is the top speed the object can reach via its own acceleration on flat ground.
    • "Hard Max Speed": Essentially the old Max Speed property. The object simply will not move higher than this speed, horizontally. Best not to make this too high, as if you reach these speeds it'll likely start clipping through solids.
    • "Friction": Renamed "Deceleration" property. Effectively passive deceleration, slowing the player when no input is present.
    • "Deceleration": Active deceleration, slowing the player when their input is in the opposite direction of their movement.
    • "Air" versions of several of the above: Take effect when the player isn't on the floor. Mostly optional so as not to require swapping things around in events all the time.
    • "Rolling" versions of several of the above: As with the "Air" versions, these apply when the player is rolling. Of note is that acceleration is set by default to 0, though this isn't necessary.
    • "Roll threshold": The speed at which the player must be moving to be able to roll.
    • "Unroll threshold": The speed below which the player will revert back out of a rolling state.
    • "Uphill slope factor": The rate at which an uphill slope slows the player.
    • "Downhill slope factor": The rate at which a downhill slope will speed up the player. If both are identical, then the player will remain at essentially the same speed after going down and up to identical slopes, if not factoring acceleration if they go below the soft max speed.
    • "Roll" versions of slope factor. To get the effect of rolling giving more acceleration, have uphill factor be significantly lower than downhill.
    • "Wall Speed Threshold": The speed below which the object will lose its grip when moving on a wall or ceiling surface.
    • "Max jump speed": I've changed the variable jump height setup so that instead of moving at a constant rate when the jump key is held (like the Platform behaviour), there is a maximum jump and a minimum jump, with the engine automatically giving you something inbetween if the jump key is released between the two. This is done because A: it's more accurate to the Sonic games and B: It gives a more parabolic jump curve.
    • "Min jump speed": As above. Should obviously remain lower than max jump speed, or identical if no variable jumping is desired.
    • "Rolling Enabled": Set to quickly disable rolling. Same effect can be acquired by disabling default controls and simulating all but the roll key, but this is quicker. This will also effectively disable any rolling-related actions.
    • "Rolling jump control lock": In some Sonic games, jumping while rolling would lock the controls. It's enabled by default for accuracy's sake, but it could definitely be undesireable so it's optional.
    • "Set Angle": Whether the object will rotate at 90 degree intervals when moving across slopes. NOTE: Not currently working yet. I want to make it offset the position so as not to cause the object to clip into or off of collision polys but that's not quite done yet.
    • "Air Drag Rate": The amount X speed is multiplied by each 1/60th of a second, under certain conditions.
    • "Air Drag Y Threshold": Y Speed, in pixels per second, above which Air Drag is applied. Must be below 0.
    • "Air Drag X Threshold": X Speed, in pixels per second, above which Air Drag is applied.
    • "Downhill Slope Factor Threshold": Distance, in degrees, from 0, under which downhill slope factor will not be applied.
    • "Uphill Slope Factor Threshold": Distance, in degrees, from 0, under which uphill slope factor will not be applied.
    • "Falling Angle Threshold": The lowest angle of terrain the object can fall off of.

    TODO:

    Rotate the object at 90 degree intervals while moving

    Add smoothAngle expression (and X/Y offsets) to allow smooth rotation on slopes

    Allow objects to move with a rotating Solid object (think seesaws)

    Make TileMaps work. See Known Issues!

    Known Issues:

    Tilemap doesn't work! Tilemaps use an array of collision polys (I think) rather than just a poly or bounding box, and I'm still working on making that work. If anyone knows a simple way to get the relevant collision poly from a tilemap via the sdk, please let me know! Should be fixed in the next release, provided I can figure this out. For the time being, I'd suggest making tilemaps not solid, and having solid sprite objects act as collision.

    Changing Angle of Gravity can mess with things. This is definitely something I want to fix (Mario Galaxy planets with Sonic Physics, anyone?) but with the behaviour being as complicated as it is it may take a bit of time.

    Possibly the most important one: Intended for use with Sprites with collision polygons set to bounding box. Preferably square, but that's just so that all sides are even, since the behaviour doesn't yet rotate the object. The methods I used for getting points of collision are somewhat shonky and "good enough", but I'd prefer to redo them at some stage (which also ties in somewhat to the tilemap stuff). For now, the behaviour works best if you have a rectangular Sprite. For rotation, you can have another Sprite pinned to it that changes angle along with the SurfaceAngle expression.

    If you have any feedback, requests, or bug reports, please share them in this thread!

    It's worth noting that this is the first Construct 2 addon I've worked on, as well as the first time I've played around with javascript, so if anyone with more experience in either of those things has suggestions for improving this, I'd be happy to hear them!

    Update: Release 1.0.3

    Changes:

    -Set Soft Max Speed now works

    -Vector Y is no longer capped to Min Jump Strength if jump button isn't held (should allow springs and bumpers to work)

    -Rolling Jump Control Lock now functions if enabled

    -Removed Is Double Jump Enabled condition

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Do you have the example's capx ? I'm trying this on a new project, but sometimes the player rectangle gets stuck on slopes, no idea why...

  • importing the addon return me the error message:

    missing folder in .zip

  • blackant I had the same problem. renaming the file to .zip and extracting manually solves it. but PixelMonkey might wanna look into it.

  • KZR thanks for the tip

  • Whoops. Yeah the c2addon file was wrong, should be fixed now! I've also added the example capx, though at the moment it's very basic.

  • This is a thing of beauty! And when I checked - the event sheet was empty - lol.... Not an overlap or collision check in sight. Sigh... I can see myself dividing my time between 2 projects soon.

  • Thanks! Yeah, no events yet, though I'd like to add some as some examples of extending the behaviour via events like you would the Platform behaviour, but for the essentials it's as simple as assigning the behaviour to a Sprite!

  • no comment.....

    love it ... its pretty useful for slopes like games, had some problems some times ago for a rope game that needed some cool detection since the rope will bend around an heavy round object thanks man il give it a try

  • About freaking time! My previous attempts at making Sonic physics via events haven't gone so well, so to see this one running so accurately and beautifully. It makes me want to get back to using C2.

  • Candescence: Thanks! I've had 2 or 3 attempts at making an event-based system myself, but the whole thing failed to hold up with even the basics, and doing it via a behaviour seemed far more sensible and user-friendly.

  • Candescence: Thanks! I've had 2 or 3 attempts at making an event-based system myself, but the whole thing failed to hold up with even the basics, and doing it via a behaviour seemed far more sensible and user-friendly.

    And probably a lot more efficient performance-wise, I'd imagine.

  • Yeah I'd certainly say so. As far as I can tell I've done things in much the same way as the Platform behaviour, so there shouldn't be much impact.

  • Great!!!

    Youve done it

    So much options to set in your behavior, truly great.

    • - - claps slowly - - -

    You good Sir Knight are a true Master of the Art.

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