Gradual Increase in Running Speed

0 favourites
  • 6 posts
From the Asset Store
Full game Construct 2 and Construct 3 to post on Google Play
  • Hello everybody!

    I'm pretty new to Construct 2 and have a question regarding my Mario-ish platformer. In Mario, when the run button is held, Mario's speed gets gradually quicker until he hits max speed. Is there a way to replicate this in Construct 2? The answer may be simple, but, like I said, I'm new to this.

    Thanks in advance!

  • What behavior are you using for the movement?

  • ,

    Whichever behaviour you're using, it'd be worth familiarising yourself with the 'clamp' expression - it's very useful for a bunch of situations in which you want to constrain a variable between a minimum and maximum value.

    It takes the form clamp(value, max, min). The handy thing is that the 'value' part can be a variable or expression itself. So in your case, for example you might have a 'speed' instance variable on Mario. You could then use the following code:

    On right arrow down: Set Mario.speed to clamp(self.speed+1,-10,10); Set Mario.X to self.X+self.speed

    On left arrow down: Set Mario.speed to clamp(self.speed-1,-10,10); Set Mario.X to self.X+self.speed

    This would increase or decrease Mario's speed by 1 each tick depending upon which direction key is held down and then move Mario in the given direction.

    Remember to reset the speed to 0 when no key is pressed, or divide the speed each tick after release to allow deceleration.

    Alternatively check out the 'max' and 'min' expressions in the manual - they can be used in a similar way to limit the range of a variable.

    You should also familiarise yourself with using dt time to ensure frame rate independent movement - there's a bunch of tutorials, forum posts and manual entries on how to use it - a quick search should point you in the right direction.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks!

  • You're welcome

  • Just so you know.

    Most movement behaviours have a build in 'clamp' system.

    Meaning, they have a 'max speed'. Or, speed is clamped to that maximum.

    Just calculate/experiment the acceleration to your needs.

    The acceleration is a natural log. Not linear as in 'speed+1'

    https://www.dropbox.com/s/nnbjt6fupz580 ... .capx?dl=0

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