I'm not sure if anyone has played Mother 3, but I'd like to try and make a similar sprinting mechanic.
I'd like it to work so that when you hold down "X" for 1 full second your character's sprite changes to the "ready position." While holding "X" and in the "ready position" you can use the arrow keys to alter you hero's facing without moving. Now when you release "X" you sprint in that direction (your speed is increased). If you then run in to a wall, NPC etc... or if you change direction while sprinting then you will return to normal walking speed.
This seems a bit difficult to fulfill so many conditions. I'm certain I'll need a timer to check if the "X" button is held for 1 sec but asides from that I'm a bit lost.
I just want to see if there is a simple solution or direction before I spend a bunch of time working away at this.
How: Sprint game mechanic like Mother 3
Moderators: marionline, SDHawk
- sheamkennedy
- Liquid Metal Slime
- Posts: 1110
- Joined: Mon Sep 16, 2013 9:29 pm
- Location: Tama-shi, Tokyo, Japan
- Contact:
How: Sprint game mechanic like Mother 3
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
â� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
â� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
It sounds like you have everything thought through. You can just do as you said, set a timer when the player presses x, then at the end of it run a script that sets a tag or a variable. If that tag/variable is true, you set the player's speed to fast and outside battle picture accordingly.
You would also want to set a check to see if the player is moving at all, and set the tag/variable false if not.
Are you using default movement or did you write a special plotscript for pixel-based movement? That would make the solution very different.
You would also want to set a check to see if the player is moving at all, and set the tag/variable false if not.
Are you using default movement or did you write a special plotscript for pixel-based movement? That would make the solution very different.
My pronouns are they/them
Ps. I love my wife
Ps. I love my wife
Using timers is always more work than just using 'wait's, often far more. Note that you need to check the key state every tick during the second, you can't just set a timer for a second in the future (unless you want to allow tapping instead of holding the key). So I recommend only using timers if it's necessary because of problems with other scripts interfering (getting triggered and pausing your 'run' script). So to work out the easiest way to script this it's necessary to consider what should happen in the edge cases:
- when you run onto a door
- are they any step-on npcs you could run onto that would trigger a script or a textbox
- do you have any other scripts containing while-wait loops that need to continue while the player is running?
- are there any other things the on-key-press script needs to do, or can you disable it for the duration?
Even if the engine supported running multiple scripts at once, that would only solve a couple of the problems.
You will want to write a script which you can call at the beginning of every cutscene or other script that should interrupt running, which cancels the run, setting the player walkabout graphic and speed back to normal. If you use timers then you can just unset the timer with "stop timer". If you instead have a single script with a couple while-wait loops, then you should just put a check in each of those loops like "if (running cancelled) then (exit script)".
- when you run onto a door
- are they any step-on npcs you could run onto that would trigger a script or a textbox
- do you have any other scripts containing while-wait loops that need to continue while the player is running?
- are there any other things the on-key-press script needs to do, or can you disable it for the duration?
Even if the engine supported running multiple scripts at once, that would only solve a couple of the problems.
You will want to write a script which you can call at the beginning of every cutscene or other script that should interrupt running, which cancels the run, setting the player walkabout graphic and speed back to normal. If you use timers then you can just unset the timer with "stop timer". If you instead have a single script with a couple while-wait loops, then you should just put a check in each of those loops like "if (running cancelled) then (exit script)".
Last edited by TMC on Sat Sep 24, 2016 2:53 pm, edited 1 time in total.
- sheamkennedy
- Liquid Metal Slime
- Posts: 1110
- Joined: Mon Sep 16, 2013 9:29 pm
- Location: Tama-shi, Tokyo, Japan
- Contact:
Thanks a lot both. I'm sorry for the late response, I've been sick the past while and wasn't really feeling up to much computer stuff or coding. I have now had a chance to use your suggestions to implement this code and so far it seems to be working well. I do still have to perform some edge cases, step-on NPC's and player input interrupts in particular so hopefully those won't be too hard to handle. I'll let you know if I run in to any issues.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
â� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
â� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases