So, I currently have it so when I press the “z” key, Mario’s max horizontal speed increases to about double the original, hence running. The only problem is that this reaction is immediate, meaning that he goes from walking speed to a full sprint, and immediately back to walking after the key is released. My question is, is there a way to make it so the speed gradually builds up and caps off at a certain speed, then when the key is released, Mario slows down gradually as well?
Would this also be able to work in a lesser way to make it so Mario also gradually gets to walking from idle, instead of immediately?
Maybe you can use the tweening functions?
No, that wouldn’t work. I still need to have him be a platformer character.
Doesn’t the platform behavior have acceleration and deceleration parameters? Is there an issue with it? You could make it dynamic so the values are based on current speed or something.
Are you change the speed or the max speed?
It does, but I’m pretty sure making them dynamic is what I’m actually asking about. I’m changing the max speed, but there has to be some way to code it so that Mario increases speed a little at a time.
Does changing the max speed cause Mario to immediately move at the max speed? If so, then maybe if you slowly increase the max speed with max speed + a number while the run key is pressed until it reaches a certain value. IDK if you need to multiple the number being added by TimeDelta() to make sure it’s smooth.
I kinda see where you’re going with this, but could you maybe put it in somewhat simpler terms? I don’t really know how to properly add a value that increases every certain increment, much less how to cap it off at a certain value. Multiplying the number by TimeDelta() would increase the speed forever, and I know that because I tried it. If that is the right direction to go, then I need to know how to cap off the value when it gets to a certain number.
This seems to work, the fist event shows the current speed and max speed, I used abs() to keep it positive and trunc() to remove the decimals.
the 2nd slowly increases as long as a key is pressed and the max <= 500, it uses min() to prevent it from going over 500 in case of something like 495+20, it would be 500 instead of 515
The last event slowly decreases the max as long as the key isn’t pressed and max > 250.
The values can be whatever. You can increase and decrease at different speeds.
Not quite… I need Mario to decrease speed when releasing the key/key isn’t pressed. Right now, he does accelerate up to max speed okay, but when Z key is released, he doesn’t slow back down. But we ARE getting there.
EDIT: Maybe I should make it clear, I release the Z key, but I still have “Right” pressed down in order for Mario to keep moving. What I want is for that speed to decrease somewhat fast while he’s still moving, but the Z key is released, if that makes sense. Basically I want to get it to a feel close to the original Super Mario Bros.
If you inverted the last line then it should be. [inverted] key is pressed
Is it not the same as “key released”? I tried it with both and the results seemed identical.
If key is pressed is inverted. it’s the opposite of key is pressed meaing is not pressed. Key released only triggers once. You could use a boolean with it or a tween but it’s just as easy to check the key.
For “TimeDelta(),__” what are the numbers’ significance? Do higher numbers mean it takes longer to execute the action?
Okay, I see. So, I think I’ve managed to get a smooth acceleration and deceleration going by messing with the default acceleration value inside the PlatformerCharacter behavior and using your suggested string to decrease the max speed incrementally, so it’s kind of a work-around, but it works for me!
Now, one last thing. Would there be a way to detect if Mario is still moving right but left is being pressed, and vice versa? If I can figure out how to utilize that info, I sincerely believe that with a few small tweaks, it’ll help with giving Mario a skidding animation and making sure that animation doesn’t trigger if he’s turning around while only at walking speed. To be specific, I’m talking about this little frame of animation where Mario skids across the ground and prepares to run the opposite direction:
I guess it could be something like this. if the horizontal speed is > 0 , mario is going right and if it’s < 0 then mario is going left. So, check the oppisite key or contol
Almost… now I need an event to stop Mario’s skid animation. I might be able to figure it out myself, but if you have any better ideas, shoot.
I have no ideas on that one.