walk run

Get help using Construct 2

Post » Thu Jan 10, 2013 7:44 pm

i want to do: a+keyleftor right run and key left or right walk(platform game)
what is the easiest way to do that , should have to use variables?
B
6
Posts: 28
Reputation: 831

Post » Thu Jan 10, 2013 10:45 pm

What I have been doing for this is just to make some adjustements to my event sheets. I created 2 variables, one called playerBaseSpeed and one called playerRunSpeed. I set playerBaseSpeed to whatever my normal walking speed is, and playerRunSpeed to whatever my running speed is, in my case base is 330 and run is 600. I then have an event for my run button keydown event where if it is down the speed is set to playerRunSpeed, else it is set to playerBaseSpeed. This seems to work well for me so far. The next thing I need to do is set the animation speed when he is running so the legs moving matches the new speed a bit better.

This has a few benefits, I don't have to alter my keyleft or right events since the Run button (in my case B) handles the speed changes as needed. Also I can add extra logic later for example what if I have a powerup that ups the run speed even more? Then I can have an event that says if speedPowerUp is on, set playerRunSpeed to 900, else set it to 600. This gives you a lot of flexibility. You could also create constants for basespeed and runspeed if you want, then in your events you could just reference those if you don't see a need to change them.BluePhaze2013-01-10 22:48:23
B
49
S
11
G
10
Posts: 1,833
Reputation: 14,428

Post » Fri Jan 11, 2013 5:14 am

ok i guess you add your two variables in the object , i'm confusing about the code can you write it?
i guess
variable is run: set speed at 600
variable is walk set speed at 300
key left : set variable to walk
key left+a : set variable to run
B
6
Posts: 28
Reputation: 831

Post » Fri Jan 11, 2013 5:32 am

Here is how I have it setup in my Event Sheet, I am very new to construct 2, so if anyone has a more efficient way let me know. My background is as a developer so I am used to writing it in code as opposed to event sheets. Here is how my event sheet is setup:

I have two global variables in my eventsheet:

Global number playerRunSpeed = 600
Global number playerBaseSpeed = 330

I then have an event for the player holding the run button:

Keyboard B is down Player Set Platform maximum speed to playerRunSpeed
System Else Player Set Platform maximum speed to playerBaseSpeed

It doesn't matter if they have the left or right arrow down, as long as they have the B button held down, the maximum player speed is set to my run speed. If they are not moving this doesn't do anything, if they are moving they get the new maximum speed. You can also play with this a bit by setting the acceleration, etc... as needed if you want them to not instantly be going max speed when you hit the run button. I have also attached a screenshot of how it looks in my event sheet on skydrive, but as I am new to the scirra site I cannot post links yet. If you want me to send you the screenshot via email or some other method just let me know.BluePhaze2013-01-11 05:35:05
B
49
S
11
G
10
Posts: 1,833
Reputation: 14,428

Post » Fri Jan 11, 2013 5:35 am

The above also has the benefit that as long as they are not holding down the run button it will set their speed back to the regular speed you chose.
B
49
S
11
G
10
Posts: 1,833
Reputation: 14,428


Return to How do I....?

Who is online

Users browsing this forum: Callan S, gamecorpstudio, getplay, Kagubro and 27 guests