Gradual Increase in Running Speed

Get help using Construct 2

Post » Tue May 30, 2017 1:21 am

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!
B
5
Posts: 5
Reputation: 235

Post » Tue May 30, 2017 11:16 am

What behavior are you using for the movement?
Like my work? Fallow me on social media, and see my games on the arcade.
B
7
S
5
G
9
Posts: 298
Reputation: 5,367

Post » Tue May 30, 2017 5:57 pm

@Nintend0Nerd,

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.
B
20
S
9
G
4
Posts: 473
Reputation: 4,260

Post » Wed Jun 21, 2017 11:37 pm

Thanks!
B
5
Posts: 5
Reputation: 235

Post » Thu Jun 22, 2017 9:29 am

You're welcome :)
B
20
S
9
G
4
Posts: 473
Reputation: 4,260

Post » Thu Jun 22, 2017 7:51 pm

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
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 9 guests