Discuss Scratch

Esteban_lightning
Scratcher
4 posts

How to make a Sprite Jump

I am trying to make a game but I dont know how to make my sprite jump or wall jump please help me
Rohancg
Scratcher
72 posts

How to make a Sprite Jump

there are a lot of platformer engines that use many different types of jump codes
newblucat
Scratcher
100+ posts

How to make a Sprite Jump

h e l o t h e r e
OLIVI3932J
Scratcher
39 posts

How to make a Sprite Jump

well, use gravity, like when green flag clicked, go to somewhere….. then something like that, or create costumes of the sprite jumping
Esteban_lightning
Scratcher
4 posts

How to make a Sprite Jump

I still dont understand what to do
\
mahi1309
Scratcher
32 posts

How to make a Sprite Jump

https://scratch.mit.edu/projects/457099660https://scratch.mit.edu/projects/457099660
heres the link of my game in which i have made my sprite jump.you can copy the code
scritchscrutch
Scratcher
32 posts

How to make a Sprite Jump

Esteban_lightning wrote:

I am trying to make a game but I dont know how to make my sprite jump or wall jump please help me
-

Hi! There's numerous ways of making a sprite jump & even going further to make it realistic/smooth with physics but a simple way to start out, you can do this & explore from there:

when green flag clicked
forever
if <key [space v] pressed?> then
glide (0.1) secs to x: (0) y: (75)
glide (0.1) secs to x: (0) y: (0)
end
end

The above means:
When the flag is clicked, whenever spacebar is pressed, it'll make the sprite move up & back down again to it's original position if it starts out at x = 0 , y = 0.

You can simply change the height of the jump by changing the 'y value'!
NMario84
Scratcher
1000+ posts

How to make a Sprite Jump

While the above code works, it it much TOO simple and unrealistic. There’s no actual gravity or physics. That’s just a generic movement code.
I would expand on that and experiment with actual gravity movement with variables.
scritchscrutch
Scratcher
32 posts

How to make a Sprite Jump

NMario84 wrote:

While the above code works, it it much TOO simple and unrealistic. There’s no actual gravity or physics. That’s just a generic movement code.
I would expand on that and experiment with actual gravity movement with variables.
-

Yes correct, as mentioned it's a simple way to start out & OP can explore from there.

I believe in giving solutions that is simple enough rather than overwhelming a potentially still learning Scratcher. If they want a more realistic & complex approach after that, we can always expand on it in the later stages. There is no such thing as ‘too simple’, if it works it works. We should always start out simple & work our way up.
Equalwing
Scratcher
12 posts

How to make a Sprite Jump

this is the easiest way to make a sprite jump
when this sprite clicked
repeat (10)
change y by (10)
end
repeat (10)
change y by (-10)
end
supergamer10000
Scratcher
1000+ posts

How to make a Sprite Jump

Ues a tutorial
F-Botics
Scratcher
36 posts

How to make a Sprite Jump

This is kinda like a flappy bird jump
when green flag clicked
forever
if <key [space v] pressed?> then
change y by (20)
end
end
when green flag clicked
forever
if <not <touching [ground v] ?>> then
change y by (-5)
end
end
Esteban_lightning
Scratcher
4 posts

How to make a Sprite Jump

scritchscrutch wrote:

Esteban_lightning wrote:

I am trying to make a game but I dont know how to make my sprite jump or wall jump please help me
-

Hi! There's numerous ways of making a sprite jump & even going further to make it realistic/smooth with physics but a simple way to start out, you can do this & explore from there:

when green flag clicked
forever
if <key [space v] pressed?> then
glide (0.1) secs to x: (0) y: (75)
glide (0.1) secs to x: (0) y: (0)
end
end

The above means:
When the flag is clicked, whenever spacebar is pressed, it'll make the sprite move up & back down again to it's original position if it starts out at x = 0 , y = 0.

You can simply change the height of the jump by changing the 'y value'!
I need a little better code
scritchscrutch
Scratcher
32 posts

How to make a Sprite Jump

Esteban_lightning wrote:

I need a little better code
-

Do elaborate on the type/feature of jumps you want & even share the game project so we can help provide with more elaborate codes that is suitable for your game!
NMario84
Scratcher
1000+ posts

How to make a Sprite Jump

scritchscrutch wrote:

-Yes correct, as mentioned it's a simple way to start out & OP can explore from there.

I believe in giving solutions that is simple enough rather than overwhelming a potentially still learning Scratcher. If they want a more realistic & complex approach after that, we can always expand on it in the later stages. There is no such thing as ‘too simple’, if it works it works. We should always start out simple & work our way up.

Alright, that's fair enough.

I already posted my jump code in at least 2 other topics anyway. It's a little more advanced, and a little more realistic with a gravity variable, but I'll let them decide what they want.
LightningTPN
Scratcher
90 posts

How to make a Sprite Jump

Use variables:

forever
change y by (velocity y)
change [ velocity y] by (-1)
if <key [ space v] pressed?> then
set [ velocity y] to [20]
end
end

You have to add a bit more code to make it stand on something and not fall endlessly.

Last edited by LightningTPN (Oct. 23, 2021 05:03:43)

Esteban_lightning
Scratcher
4 posts

How to make a Sprite Jump

a little more code because i dont know how to make it jump off any object
winterwolfy
Scratcher
1000+ posts

How to make a Sprite Jump

Esteban_lightning wrote:

a little more code because i dont know how to make it jump off any object

this should work

when [up arrow v] key pressed
repeat (3)
change y by (3)
end
repeat (3)
change y by (-3)
end

and if its touching do the same thing but with

when [ up arrow v] key pressed
if <touching [sprite? v] ?> then
repeat (3)
change y by (3)
end
repeat (3)
change y by (-3)
end
end

Last edited by winterwolfy (Oct. 30, 2021 14:40:21)

TechenrykAnimations
Scratcher
47 posts

How to make a Sprite Jump

The easiest way to do it would be

when [up] key pressed
repeat (...)
change y by (10)
end
repeat (...)
change y by (10)

end

Last edited by TechenrykAnimations (Oct. 30, 2021 15:31:09)

helloworldbyeworld
Scratcher
1000+ posts

How to make a Sprite Jump

Esteban_lightning wrote:

a little more code because i dont know how to make it jump off any object
To make it jump off an object, you will have to make it fall until it reaches the ground. Try this script:

when [space v] key pressed // when you want to jump
set [y vel v] to (10) // change this to adjust how tall you want the sprite to jump (10 gives 55px of upwards movment)
repeat until <touching [platform/ground v] ?>
change [y vel v] by (-1)
change y by (y vel)
end

This script is not much more complicated than the simplest up-down jump script, yet it includes gravity and also lets you jump to a platform of a different height, so I highly recommend you to try it. Also, you should take a look at my platformer for some useful scripts: https://scratch.mit.edu/projects/415577135/

Last edited by helloworldbyeworld (Oct. 30, 2021 16:13:25)

Powered by DjangoBB