Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » platformer games
- aIamations
-
2 posts
platformer games
I'm struggling to make a Platformer without my character bugging to the top of my screen and staying stuck there. My character also just gets stuck on the side of the platforms, and I'm trying to figure out how to make a walk animation. (i already have designs for walk) Any tips?
- tidelgl
-
100+ posts
platformer games
Here's the core physics system you need:
when green flag clicked
forever
if <key [left arrow v] pressed?> then
point in direction (-90)
change [x velocity v] by (-1)
set [x velocity v] to ((x velocity) * (0.8)) // friction
end
if <key [right arrow v] pressed?> then
point in direction (90)
change [x velocity v] by (1)
set [x velocity v] to ((x velocity) * (0.8)) // friction
end
if <key [up arrow v] pressed?> and <touching [Ground v] ?> then
set [y velocity v] to (12) // jump strength
end
...// Apply gravity
change [y velocity v] by (-1)
....// Move horizontally
change x by (x velocity)
if <touching [Platform v] ?> then
change x by ((0) - (x velocity)) // undo movement if collision
set [x velocity v] to (0)
end
// Move vertically
change y by (y velocity)
if <touching [Platform v] ?> then
change y by ((0) - (y velocity)) // undo movement if collision
set [y velocity v] to (0)
end
// Animation
if <(x velocity) > [0]> or <(x velocity) < [0]> then
next costume
wait (0.1) seconds
else
switch costume to [idle v]
end
end
Key Fixes for Your Problems
// 1. Prevent Top-of-Screen Sticking
// Add this to limit vertical movement
if <(y position) > [180]> then // near top of screen
set [y position v] to (180)
set [y velocity v] to (0)
end
// 2. Better Platform Collision
// More precise collision checking
define Check Collision
set [safe move v] to [yes]
change x by (x velocity)
if <touching [Platform v] ?> then
set [safe move v] to [no]
change x by ((0) - (x velocity)) // go back
set [x velocity v] to (0)
end
// 3. Walk Animation System
when green flag clicked
forever
if <(x velocity) > [0.5]> or <(x velocity) < [-0.5]> then
if <(animation timer) > [0.2]> then // control animation speed
next costume
set [animation timer v] to (0)
else
change [animation timer v] by (0.1)
end
else
switch costume to [idle v]
set [animation timer v] to (0)
end
... // end
end
more tips:
- Animation Basics: https://en.scratch-wiki.info/wiki/Animations
Last edited by tidelgl (Sept. 16, 2025 11:35:02)
- 0CookieBoy0
-
1 post
platformer games
can you help me with this I want to make wall jumping https://scratch.mit.edu/projects/1204792691
- Discussion Forums
- » Help with Scripts
-
» platformer games