Discuss Scratch

that_scratch_boi
Scratcher
8 posts

How to make top-down movement with WASD/arrow keys?

I'm making a top-down camera-styled game that I can't figure out how to make the movement in. I could make it point-and click, but that leads to a lot of bugs, most of which I can't fix. Besides, WASD/arrow key movement is better in my opinion. I'm not looking for something that lets the player move a certain amount in a certain direction each time a key is pressed, I would like a script that keeps the player in motion while the key is held down. Physics such as acceleration and gradually slowing down when the key is released aren't neccecary, but would be appreciated. If needed, I can provide a link to what I have as the layout of the first room. Remember, this is a top-down game, so I need there to be no gravity effects in the movement (this might seem obvious but i've gotten a lot of recommendations for regular platformer movement that use gravity and to be honest, I don't understand huge clumps of code so I wasn't able to simply find the gravity effect and remove it).
BetaBuilds
Scratcher
9 posts

How to make top-down movement with WASD/arrow keys?

I think this fits your description-
Movement Code (with physics!)

Last edited by BetaBuilds (April 1, 2024 23:27:09)

that_scratch_boi
Scratcher
8 posts

How to make top-down movement with WASD/arrow keys?

@BetaBuilds This is perfect, TY!
that_scratch_boi
Scratcher
8 posts

How to make top-down movement with WASD/arrow keys?

BetaBuilds wrote:

I think this fits your description-
Movement Code (with physics!)
If you don't mind, can you also make it so the player cannot walk through the sprite “walls n stuff”? Thanks in advance!
https://scratch.mit.edu/projects/992881015
MrKingofScratch
Scratcher
100+ posts

How to make top-down movement with WASD/arrow keys?

replace the movement blocks with this code
(this is the code for change x)
change x by (amount in project)//if replacing a change y block, use change y by __
if <touching [walls n stuff v] ?> then
repeat until <not <touching [walls n stuff v] ?>>
change x by ((the amount in project) * (-.2))//if replacing a change y block, use change y by __
end
end

Last edited by MrKingofScratch (April 2, 2024 18:03:14)


Last edited by kaj (Tomorrow 00:00:00)
100th post!
that_scratch_boi
Scratcher
8 posts

How to make top-down movement with WASD/arrow keys?

MrKingofScratch wrote:

change x by ((the amount in project) * (-.2))//if replacing a change y block, use change y by __
What does amount in project mean?

Last edited by that_scratch_boi (April 2, 2024 18:07:30)

Powered by DjangoBB