Discuss Scratch

mlpnkobji53
Scratcher
2 posts

I need help with a platformer jump code

In my game i tried to make a jump code but its not very smooth and it doesn't work well either so i need some help… mabe someone could post the jump code?

Last edited by mlpnkobji53 (Sept. 21, 2021 14:17:46)

Thingied
Scratcher
1000+ posts

I need help with a platformer jump code

Smooth (as in with gravity) jump script:
when green flag clicked
set [Yv v] to [0]
forever
change [Yv v] by (-1) // Gravity
change y by (-1) // Since it's 1 pixel off the ground, move down one to detect the collision
if <<<touching[level v]?>and<(Yv)<[0]>>and<key[jump key v]pressed>> then // If it's touching the ground and the key to jump is pressed, jump
set [Yv v] to (jump power::grey) // Gray blocks are placeholders
end
change y by (1)
change y by (Yv) // Yv is the Y momentum so you have to move whatever it is
if<touching[level v]?> then
get out of level // Running without screen refresh so it does everything instantly
end

define get out of level
repeat until <not<touching[level v]?>>
change y by (()-((Yv)/([abs v] of(Yv)))) // Go the opposite way (the divide part will report 1 if the number is positive then move the other way (-1) because 0 - 1 is -1 and vise versa)
end
set [Yv v] to [0] // Reset the velocity because there's no point in trying to move if you can't
Unixy-Code
Scratcher
500+ posts

I need help with a platformer jump code

mlpnkobji53 wrote:

In my game i tried to make a jump code but its not very smooth and it doesn't work well either so i need some help… mabe someone could post the jump code?

Find tutorials, before you ask search forum and internet. These are some results:
playlist of tutorials
engine code- any engine



also please use this option in scratch…

Powered by DjangoBB