Discuss Scratch

brownotter46
Scratcher
10 posts

Adding Gravity To A Sprite

Adding Gravity To A Sprite

Hello! If you want to add gravity to any of your projects, then you've come to the right place!

Let's get started! So first, you obviously need a sprite. Then you create this script:
when green flag clicked
if <key [up arrow v] pressed?> then
set [velocity v] to [0]
set [y target v] to (y position)
repeat (5)
change y by (10)
end
change [velocity v] by (1)
change y by (join [-] (velocity))
repeat until <(round (y position)) = (round (y target))>
change [velocity v] by (1)
change y by (join [-] (velocity))
end
if <not <(round (y position)) = (round (y target))>> then
set y to (y target)
end
end
So, now that that step is over, you can enjoy your sprite with gravity.
Also, if you are new to Scratch™, then no, that does not mean that you get a
can of soda if you view this.
ROBOTDENVER
Scratcher
7 posts

Adding Gravity To A Sprite

i use scrach 3.0 i ges its not compatible:
AFNNetworkK12
Scratcher
1000+ posts

Adding Gravity To A Sprite

ROBOTDENVER wrote:

i use scrach 3.0 i ges its not compatible:
Please don't necropost.
_Klx_
Scratcher
2 posts

Adding Gravity To A Sprite

ROBOTDENVER wrote:

i use scrach 3.0 i ges its not compatible:
i know
ROBOTDENVER
Scratcher
7 posts

Adding Gravity To A Sprite

yoor write _Klx_
Roberttvn
Scratcher
32 posts

Adding Gravity To A Sprite

hello
ROBOTDENVER
Scratcher
7 posts

Adding Gravity To A Sprite

AFNNetworkK12 wrote:

ROBOTDENVER wrote:

i use scrach 3.0 i ges its not compatible:
Please don't necropost.
what is necropost remember I said some thing on untitled- 98
Exsnailabur
Scratcher
38 posts

Adding Gravity To A Sprite

broadcast [ The lies begin][scratchblocks]
when green flag clicked
say [it don't work] for (2) secs
ask [Any other ideas] and wait
go to x: (away from liars) y: (away from liars)
[/scratchblocks]
when I receive [the lies begin]
forever
<[Me] = [Scream]>
end

Last edited by Exsnailabur (Feb. 20, 2020 23:35:19)

Exsnailabur
Scratcher
38 posts

Adding Gravity To A Sprite

brownotter46 wrote:

Adding Gravity To A Sprite

Hello! If you want to add gravity to any of your projects, then you've come to the right place!

Let's get started! So first, you obviously need a sprite. Then you create this script:
when green flag clicked
if <key [up arrow v] pressed?> then
set [velocity v] to [0]
set [y target v] to (y position)
repeat (5)
change y by (10)
end
change [velocity v] by (1)
change y by (join [-] (velocity))
repeat until <(round (y position)) = (round (y target))>
change [velocity v] by (1)
change y by (join [-] (velocity))
end
if <not <(round (y position)) = (round (y target))>> then
set y to (y target)
end
end
So, now that that step is over, you can enjoy your sprite with gravity.
Also, if you are new to Scratch™, then no, that does not mean that you get a
can of soda if you view this.

turn cw (Away from this liar) degrees
 

This don't work, DO SOMETHING NEW!!!!!!!!!!!!!!!:mad::mad::mad::mad::mad::mad::mad::mad::mad::mad::mad::mad::mad::mad::mad::mad::mad::mad::mad::mad::mad::mad::mad:
say [I AM GOING CRAZY!!!!!!!!!!!!!!!]
UndertaleD0g
Scratcher
1 post

Adding Gravity To A Sprite

Same
Exsnailabur
Scratcher
38 posts

Adding Gravity To A Sprite

You guys are overcomplicating it. Here is a sprite with a script that worked with 0 variables.



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

it is so simple.
AdamTimmy
Scratcher
100+ posts

Adding Gravity To A Sprite

Can you do mobile gravity?
Penguin137
Scratcher
25 posts

Adding Gravity To A Sprite

I can't find the round block
LittleCoder06
Scratcher
54 posts

Adding Gravity To A Sprite

Penguin137 wrote:

I can't find the round block

The round block is in the operators' category above the “abs of ()” block and after the “() mod ()” block
catdog1474
Scratcher
11 posts

Adding Gravity To A Sprite

THANK you! PS YOU NEED A SCRIPT WHERE IF YOU TOUCH THE GROUND YOU DON'T FALL THROUGH IT
LittleCoder06
Scratcher
54 posts

Adding Gravity To A Sprite

This is the code i used:

when green flag clicked
forever
if <key [up arrow v] pressed?> then
set [velocity v] to [4]
change y by (velocity)
repeat until <touching color [#000000] ?>
change [velocity v] by [-0.1]
change y by (velocity)
end
end
set [velocity v] to [0]
play sound [boing v]
end

the second code you need to put in your project:

when green flag clicked
set [velocity v] to [0]
forever
set rotation style [left-right v]
if <key [right arrow v] pressed?> then
point in direction (90 v)
move (5) steps
end
if <key [left arrow v] pressed?> then
point in direction (-90 v)
move (5) steps
end

you also need black ground as a backdrop

Last edited by LittleCoder06 (Nov. 3, 2020 11:05:22)

LittleCoder06
Scratcher
54 posts

Adding Gravity To A Sprite

LittleCoder06 wrote:

This is the code i used:

when green flag clicked
forever
if <key [up arrow v] pressed?> then
set [velocity v] to [4]
change y by (velocity)
repeat until <touching color [#000000] ?>
change [velocity v] by [-0.1]
change y by (velocity)
end
end
set [velocity v] to [0]
play sound [boing v]
end

the second code you need to put in your project:

when green flag clicked
set [velocity v] to [0]
forever
set rotation style [left-right v]
if <key [right arrow v] pressed?> then
point in direction (90 v)
move (5) steps
end
if <key [left arrow v] pressed?> then
point in direction (-90 v)
move (5) steps
end

also, you need to add a black ground as a backdrop
cs3232649
Scratcher
1 post

Adding Gravity To A Sprite

no
LittleCoder06
Scratcher
54 posts

Adding Gravity To A Sprite

cs3232649 wrote:

no
how?
FLORAIDER
Scratcher
5 posts

Adding Gravity To A Sprite

when green flag clicked
say [how u put gravity]
<[Me] = [searches how u put gravity]>
say [*gasps* i found it hehe boii]
define *clicks*
say [oke i know how :D]

Last edited by FLORAIDER (Nov. 14, 2020 12:52:01)

Powered by DjangoBB