Discuss Scratch

19gamesac
Scratcher
34 posts

is there a way to make a sprite jump

is there a code to make a sprite move into the air then come back down?
Thingied
Scratcher
1000+ posts

is there a way to make a sprite jump

Very simple example:
repeat (10)
change y by (10) // Go up
end
repeat (10)
change y by (-10) // Go back down
098765432154321
Scratcher
500+ posts

is there a way to make a sprite jump

The simple way:
when [up arrow v] key pressed // also can be set to Space key
if <(on ground) = [1]> then
set [on ground v] to [0]
repeat (10)
change y by (3) // set this to value you think is best
end
repeat until <touching [Level v] ?>
change y by (-3) // set this to value you think is best
end
set [on ground v] to [1]
end

Or use the velocity-based jump, I recommend this one the most:
when green flag clicked
set [y velocity v] to [0]
forever
change y by (y velocity)
change [y velocity v] by (-0.5) // you can change this. smaller value (ex. -0.3) = less gravity, higher value (ex. -1) = falls faster
if <touching [Level v] ?> then
set [y velocity v] to [0]
end
if <<key [up arrow v] pressed?> and <touching [Level v] ?>> then
set [y velocity v] to [6] // you can change this. smaller value = less jump height, higher value = more jump height
end
end

Didn't test but it should work
Thingied
Scratcher
1000+ posts

is there a way to make a sprite jump

098765432154321 wrote:

The simple way:
that's not very simple to me /j

098765432154321 wrote:

when green flag clicked
set [y velocity v] to [0]
forever
change y by (y velocity)
change [y velocity v] by (-0.5) // you can change this. smaller value (ex. -0.3) = less gravity, higher value (ex. -1) = falls faster
if <touching [Level v] ?> then
set [y velocity v] to [0]
end
if <<key [up arrow v] pressed?> and <touching [Level v] ?>> then
set [y velocity v] to [6] // you can change this. smaller value = less jump height, higher value = more jump height
end
end
That doesn't really work because you might be stuck/under the ground sometimes so here's the fixed version
when green flag clicked
set [y velocity v] to [0]
forever
change [y velocity v] by (-1) // I recommend setting the gravity to -1 because -.5 is kind of slow
change y by (-1) // Since the player is always going to be a pixel off the ground, you'll have to go down a pixel to detect if it's touching it when jumping
if <<key [up arrow v] pressed?>and<touching [Level v]>> then // If you put this under the change y by block, it's going to be a frame late
set [y velocity v] to [6]
end
change y by ((y velocity)+(1)) // Got to go back up after moving down
if <touching [Level v] ?> then
Y collision // Running without screen refresh
set [y velocity v] to [0]
end
define Y collision
repeat until <not<touching[Level v]>>
change y by (1) // This is to get out the ground
AntonL1kesPotato
Scratcher
1000+ posts

is there a way to make a sprite jump

Here's the script i shared in another topic:
when green flag clicked
forever
if <<<key [up arrow v] pressed?>> and <<(falling?) = (0)>>> then // if the player is falling, then he cannot jump!
set [speed y v] to (15) // higher the number, higher the jump
wait until <not <key [up arrow v] pressed?>>
end
change [speed y v] by (-1) // this simulates gravity
change y by (speed y)
check ground
end

define check ground
if <touching [platform v]?> then
change y by (1)
set [speed y v] to (0) // this prevents from the player clipping or bugging trough the platform
set [falling? v] to (0) // if the player is touching the platform, then he isn't falling!
else
set [falling? v] to (1) // if the player isn't touching the platform, then he's falling!
This probably isn't the best, but it still works good!
EpicGhoul993
Scratcher
1000+ posts

is there a way to make a sprite jump

TommyNator11 wrote:

AntonL1kesPotato wrote:

clever rockroll

TommyNator11 wrote:

Thingied wrote:

Bruh the forums are so moist now
like my moms *
Congrats on derailing the topic.

Also why not check some platformer tutorials?
MasterofTheBrick
Scratcher
1000+ posts

is there a way to make a sprite jump

Also why not check some platformer tutorials?

I'm pretty sure a platforming tutorial isn't needed for a simple jumping script
EpicGhoul993
Scratcher
1000+ posts

is there a way to make a sprite jump

MasterofTheBrick wrote:

Also why not check some platformer tutorials?

I'm pretty sure a platforming tutorial isn't needed for a simple jumping script
Well, that's kinda true.
TommyNator11
Scratcher
63 posts

is there a way to make a sprite jump

EpicGhoul993 wrote:

TommyNator11 wrote:

AntonL1kesPotato wrote:

clever rockroll

TommyNator11 wrote:

Thingied wrote:

Bruh the forums are so moist now
like my moms *
Congrats on derailing the topic.
thx!
unicorn__Donut
Scratcher
100+ posts

is there a way to make a sprite jump

if <key [space] pressed?> then
change y by (10)

Last edited by unicorn__Donut (July 12, 2021 08:25:10)

bob978321
Scratcher
78 posts

is there a way to make a sprite jump

@unicorn_Donut that would make the player fly
jdmdigital
Scratcher
100+ posts

is there a way to make a sprite jump

My basketball game has a good jump feature using “YVelosity” variable. two small scripts for it to work.

https://scratch.mit.edu/projects/552654678
cIoudyness
Scratcher
500+ posts

is there a way to make a sprite jump

jdmdigital wrote:

My basketball game has a good jump feature using “YVelosity” variable. two small scripts for it to work.

https://scratch.mit.edu/projects/552654678

(off topic: suspicious how you've spelled velocity correctly within the project but not here)
jdmdigital
Scratcher
100+ posts

is there a way to make a sprite jump

cIoudyness wrote:

jdmdigital wrote:

My basketball game has a good jump feature using “YVelosity” variable. two small scripts for it to work.

https://scratch.mit.edu/projects/552654678

(off topic: suspicious how you've spelled velocity correctly within the project but not here)


ummm…sometimes if forget how to spell. there are several words i mix up the phonetics. i get them correct some days but not on other days.

Last edited by jdmdigital (July 14, 2021 13:52:18)

Al3xScratch
Scratcher
2 posts

is there a way to make a sprite jump

when green flag clicked
go to x: (-2) y: (-129)
glide (1) secs to x: (7) y: (145)
wait (4) secs
glide (1) secs to x: (-2) y: (-129)


note: the more seconds u add the slower it is the less seconds u add the faster it is ( in the glide “ ” secs block and wait “ ” and glide “ ” secs as well )
hope this helped
lisagu-test
Scratcher
3 posts

is there a way to make a sprite jump

Al3xScratch wrote:

when green flag clicked
go to x: (-2) y: (-129)
glide (1) secs to x: (7) y: (145)
wait (4) secs
glide (1) secs to x: (-2) y: (-129)


note: the more seconds u add the slower it is the less seconds u add the faster it is ( in the glide “ ” secs block and wait “ ” and glide “ ” secs as well )
hope this helped
This is not exactly smooth

Powered by DjangoBB