Problems with "Fast" run - solved

I’ve been working on a basic platformer and I’m trying to add a run feature (right arrow is default walk, z for run). I have a player hitbox (platformer object behavior) with the actual Player attached to it. I set it up so when Z is pressed I change the Max Speed object value of the hitbox from the default 250 to 500. I added some debugging messages to confirm the logic is getting hit. I can see the value change but there is no difference in the speed of the character. I manually changed the max speed value in the hitbox object directly, still no luck. Is there something else I need to take into consideration? I am doing the logic in an external event (Player Controls) that is linked to the scene, then has the level imported as an external layout.

Mobile controls logic:

General desktop logic:


(You can see where I tried to change the actual character sprite too just to see if that help (the Player sprite does not have the Platformer Object behavior).

Secondary question, is there an easy way to show the value of the max speed object attribute (or even obtain the current value and assign it to a text) ? For my debugging I am just manually writing a value to a text object to display what I think the actual value should be.

Do I need to add this to all jump and existing walk logic, I was hoping I could just change the max speed attribute and the existing jumping and other logic would allow him to jump faster, walk ect… if the max speed attribute was modified.

For the second question I think you could make an object variable, then set the max speed to that variable by doing: "change the maximum speed of player set to Player.Variable(nameofvariable). Then you can use a text object to display it by doing: ToString(Player.Variable(nameofvariable)). My only solution for the first one would be to not use the built in controls of the platform character behavior, and instead just add a force when a certain key is pressed, and you could use a variable for the force so it would look something like: "Add to player instant force of Player.Variable(nameofthisvariable). Then you could change that variable through actions. Hope this helps

Is there anywhere you set the max speed of the hitbox, other than the keypress events? Maybe search for “250” in all the scripts, and see if that appears where you aren’t expecting it.

What happens if you change the speed to 1000 instead of 500?

Thanks @MisterBread009, was hoping to use as much of the defaults of Gdevelop as possible, but I can see where using the force would allow for more customization.

I like your idea of using the object variable to set the speed, but it sounds like there might not be a way to view or access the current value of the actual max speed attribute (is attribute the correct reference, or is it a property, variable?)

@MrMen this is the first time I’ve tried modifying the max speed, those are the only two places (mobile controls external event, and the player external event) that modify the value. I did try to change it to 5000 just to see, no difference still.

If you were to set the max speed attribute (I don’t know what it’s called either lol) to a variable constantly, that is with no condition before it, then that would ensure that the variable value is definitely the same as the max speed attribute. So checking the variable would be identical to checking the value of the attribute. GDevelop behaviors are less easily customized than built in actions, so I suggest using them as infrequently as possible.

same question… awaiting for proper reply

@MisterBread009 I tried the object variable getting assigned based on the event, then always assigning the value of that variable to the Max Run parameter (I’m going with the term parameter).

But I don’t think I am referencing the variable correctly when assigning it to the max speed, the warning said it was expecting a number, I’m confused by this one, I thought I needed to enter the name of the object variable in the .variable() function.

And therein lies the problem. If you’re using keyboard, then you’ll never be touching the run button, so it sets the speed to 250. And if you are on mobile, then the ‘z’ key is never pressed, and so that sets the speed to 250.

You’ll need to work out which input the player is using, and have a condition that only checks that one, and not both inputs methods.

Don’t put MaxSpeed in quotes, you only put text in quotes, you don’t put numbers in quotes.

Thanks for the help everyone, I got it to work by just doing all of the logic in the mobile controls area that way it was easier to ensure the correct events got hit in the right order.

I didn’t find an easy way to do an “or” within the single event, like touch is on RunButton OR z key is pressed. Do you just need to always do separate events, maybe it another one of those simple things I’ve not seen yet.

This is not the correct fix. You still have logic errors. With the events screen shot you provided, if you touch the RunButton, the “not z key pressed” event still fire. You’ve hacked this by adding an unnecessary variable. If you add any further actions like animation changes or sounds to the events, you’ll get it behaving incorrectly.

You need to determine whether the player is using touch or keyboard, and then only check the input events for what they are using. Somewhere in the start of your game set a global [boolean] variable that indicates whether input is touch or not. And use the value of that variable to either check touch or keyboard input:

GlobalVariable(UsingTouch) is true
  - button not pressed event
  - button pressed event

GlobalVariable(UsingTouch) is false
  - z key not pressed event
  - z key pressed event

But how you’ve done it now is an incorrect hack.