Hello, I just started with Scratch and I'm planning on doing a platform game. I decided to script the sprite's movement first and here's what I got:
when gf clicked set [y velocity] to [0] set [x velocity] to [0] forever if <touching color [ground color]?> if <key [up arrow v] pressed?> set [y velocity v] to (10) else set [y velocity v] to (0) end else change [y velocity v] by (-1) end if <key [right arrow v] pressed?> set [x velocity v] to (6) end if <key [left arrow v] pressed?> set [x velocity v] to (-6) end if <<not <key [left arrow v] pressed?>> and <not <key [right arrow v] pressed?>>> set [x velocity] to ( (x velocity) * (0.92) ) end change y by (y velocity) change x by (x velocity)My question is: are there easiest/better ways to do this? As far as I've tested, it works correctly, but I don't know if I'm doing it the right way.
Offline
It depends on what you want the script to do. There are more advanced scripts that can do wall detection, double jumping, etc, but if you only want ground detection and movement with acceleration, your script looks like the easiest way to me.
I'd like to point out that, if you're only using "friction" if the left and right keys aren't pressed, there is no limit on the speed the user can get to.
Offline
MoreGamesNow wrote:
I'd like to point out that, if you're only using "friction" if the left and right keys aren't pressed, there is no limit on the speed the user can get to.
What do you mean by that? I didn't understand that very well to be honest.
Offline
Fyrox wrote:
MoreGamesNow wrote:
I'd like to point out that, if you're only using "friction" if the left and right keys aren't pressed, there is no limit on the speed the user can get to.
What do you mean by that? I didn't understand that very well to be honest.
If I just hold down the right arrow, the x velocity will continue to increase without a limit.
Offline
MoreGamesNow wrote:
Fyrox wrote:
MoreGamesNow wrote:
I'd like to point out that, if you're only using "friction" if the left and right keys aren't pressed, there is no limit on the speed the user can get to.
What do you mean by that? I didn't understand that very well to be honest.
If I just hold down the right arrow, the x velocity will continue to increase without a limit.
Yep. The speed will keep increasing until you stop holding the arrow key.
Offline
Ah. I missed that. My bad
Offline
Yes, that would probably be easiest. I look forward to seeing what this is all going towards
Offline
Well I basically want to make a cool simple platform game just to learn a bit of Scratch since I just started with it, nothing really special. I've almost finished the first part of the game (movement, animation and a little point system). Later I'll have to deal with wall detection and stuff.
Offline