Walk to run and run to walk


#1

I guys,

i need help i want to make my character run when i press a key and when i release the key walk again.
Thanks


#2

Hey,

Are you using the platformer extension or basic force to move your character ?


#3

Yes, i need to know how to increase speed when i press left control for exemple and when i release the key button the character walk again.
Event , condition (press key button), action?


#4

Personally i would use a variable for example “player.speed”, with init value for example 200. Then when the key is pressed, you give the variable value to the platform behavior speed parameter.

Finally, for the “running” purpose, you can imagine something like this :
“LShift” is pressed => player.speed = player.speed*2

Do you see what kind of event condition/action to do ?

In summary, you’ll have :
“left” or “right” key pressed => player will move at speed “200”
if “LShift” and (“left” or “right”) are pressed = > speed X2


#5

Thanks for your help but i’m a noob.

I try this way,

New event
condition (Lshift key is pressed) / Action (Do = +200 to the maximum speed of the PlayerHitBox)
New event
(Lshift key is released) / Action (Do =200 to the maximum speed of the PlayerHitBox)

I don’t know if this is the correct way to do this but it Works.
But now i need to change the animation when i press the Lshift key.
Something like this…
condition (PlayerHitBox is moving) / action (Do =2 to the number of current animation of the player)


#6

The way you used it is correct, in fact it’s correct until it works or not conflicting with something else.

Just add the action on animation changing in the same event (when LShift is pressed). And same thing when the key is released : add the animation change action.


#7

I want to try your way

(“LShift” is pressed => player.speed = player.speed*2
In summary, you’ll have :
“left” or “right” key pressed => player will move at speed “200”
if “LShift” and (“left” or “right”) are pressed = > speed X2 )

maybe my problem is that i’m using a PlayerHitBox so i need to do something like this:

In the propreties of playerhitbox create a variable PlayerHitBox.speed with value 200
new event
condition (Lshift key is pressed) / action (playerhitbox.speed=playerhitbox.speed*2)

so the speed will change if only i press the Lshift button then when i release the button it will back to the normal speed that’s it? Remember i’m a beginner…


#8

check the example i’ve joint ! I commented all i’ve done, it’s just a modification of the basic platfomer example given with GD. :slight_smile:
platformer example.gdg (62.7 KB)


#9

ok i try to use your exemple but with the default keys and it Works nice, thanks.
The only problem is the animation when i press the button, the player do not run it seems like he is sliding.

Lshift key is pressed =>Do =3 to the number of current animation of player
Lshift key is released =>Do =0 to the number of current animation of player

my animations:
animation 0 “Idle”
animation 1 “Jump”
animation 2 “Walk”
animation 3 “Run”

What i’m doing wrong?


#10

Like this i don’t see error in your explanation…

Your sprites animation’s are “looping” (in the sprite edition) ?


#11

every animations are in loop mode.


#12

you might miss something… post screenshots of your events if possible, without it it’ll be hard.


#13

Maybe is a bug of the Gdevelop.
Run.jpg
Walk.jpg
events.png


#14

I got the same problem that animations does not work like they usually worked (before update). But I solved the problem like this with variables:
WalkRun.png


#15

@Jubeliuksen3: Top-secret object name, eh?, now I want to know what it’s :laughing:

@Daylong25: I’ve two words for you, “State machine” :wink:
From your events image, I guess animation 2 is “walk” and 3 is “run”. So what happens when you hold “LControl”? At each frame, GDevelop will set the animation to 2 because the conditions are met at event 5.1, and then set it to 3 because LControl is pressed (reset the animation because you switch it from 2 to 3), finally render the scene. You should see only the frame 0 of animation 3 while LControl is pressed.

To solve the problem you have to stop changing the animation to 2, you can do it with a simple state variable as Jubeliuksen3 suggests: The first time you press LControl you set a state variable “State” = “Running”, and when LControl is released set “State” = “Walking”. Finally, change to animation 2 only if “State” is “Walking”:

[code]Conditions: Player is on floor
Conditions: Player is moving
The text of variable “State” is = “Walking”
Actions: Do = 2 to animation of Player

Conditions: Player is NOT moving    // Do not change it, even if you hold Ctrl, when the player is not moving should display the stand animation
Actions: Do = 0 to animation of Player

Conditions: LControl is pressed
Actions: Do = 800 to variable “speed” of Player
Do = 3 to animation of Player
Do = “Running” to the text of variable “State”

Conditions: LControl is NOT pressed
Actions: Do = 250 to variable “speed” of Player
Do = “Walking” to the text of variable “State”[/code]


#16

For Lizard-13:

I noticed that a bit late :smiley: Hahah no secrets, if I remember right I “censored” those because they were unnecessary and might confuse people :laughing: :laughing:


#17

Hahaha no worries, ok :smiley:


#18

Very much thank you for this topic!