Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Collision with the ground
- Dylanica
- Scratcher
54 posts
Collision with the ground
I am making a game which is like minecraft but i have a problem. To make the character collide with the blocks i did something like this:
But this doesn't work very well because you can walk into the block and just hang there inside the block
Does anyone have advice?
when green flag clicked
forever
if <not <touching [ Ground] ?>> then
change y by (5)
end
end
But this doesn't work very well because you can walk into the block and just hang there inside the block
Does anyone have advice?
when I receive [Cookies v]
repeat until <(Cookies) = [ 0]>
play sound [Happy Noises v]
change [Cookies v] by (-1)
end
- Dylanica
- Scratcher
54 posts
Collision with the ground
I am making a game which is like minecraft but i have a problem. To make the character collide with the blocks i did something like this:when green flag clicked
forever
if <not <touching [ Ground] ?>> then
change y by (5)
end
end
But this doesn't work very well because you can walk into the block and just hang there inside the block
Does anyone have advice?
oops i meant
change y by (-5)
when I receive [Cookies v]
repeat until <(Cookies) = [ 0]>
play sound [Happy Noises v]
change [Cookies v] by (-1)
end
- Dylanica
- Scratcher
54 posts
Collision with the ground
is anyone going to reply?
when I receive [Cookies v]
repeat until <(Cookies) = [ 0]>
play sound [Happy Noises v]
change [Cookies v] by (-1)
end
- HOWING_test
- Scratcher
32 posts
Collision with the ground
I can help: is anyone going to reply?
when green flag clicked
set [gravity v] to [-0.3]
set [velocity v] to [0]
set [bounce count v] to [0]
forever
if <touching color [(ground color)] ?> then
if <(bounce count) < [2]> then
set [velocity v] to ((velocity) * (1)
set y to ((y position) + (velocity)
set [velocity v] to ((velocity) / (5)
set y to ((y position) + (velocity)
change [bounce count v] by [1]
else
set [velocity v] to [0]
end
else
set [veloctiy v] to ((velocity) + (gravity))
set y to ((y position) + (velocity))
end
end
This is the test account of my original account HOWING.
I use this account for tests and the forums.
Check my main account (HOWING) for projects!
Check my second account (Guggleborn14) for more projects!
Check my profile (That's me) for test projects!
Test = Support
- Dylanica
- Scratcher
54 posts
Collision with the ground
Thank you but you misunderstood my questionI can help: is anyone going to reply?when green flag clicked
set [gravity v] to [-0.3]
set [velocity v] to [0]
set [bounce count v] to [0]
forever
if <touching color [(ground color)] ?> then
if <(bounce count) < [2]> then
set [velocity v] to ((velocity) * (1)
set y to ((y position) + (velocity)
set [velocity v] to ((velocity) / (5)
set y to ((y position) + (velocity)
change [bounce count v] by [1]
else
set [velocity v] to [0]
end
else
set [veloctiy v] to ((velocity) + (gravity))
set y to ((y position) + (velocity))
end
end
I meant that you can't fall through the ground you can walk straight through walls
when I receive [Cookies v]
repeat until <(Cookies) = [ 0]>
play sound [Happy Noises v]
change [Cookies v] by (-1)
end
- MoreGamesNow
- Scratcher
100+ posts
Collision with the ground
You need to correct for both x and y collisions, ideally resolving one before the other takes place. Try something like this:
If you want more jumping, more realistic gravity, etc. let me know
when gf clicked
forever
if<key [right arrow v] pressed?>
change x by (5)
if<touching [floor or wall v]?>
change x by (-5)
end
end
if<key [left arrow v] pressed?>
change x by (-5)
if<touching [floor or wall v]?>
change x by (5)
end
end
change y by (-5)
if<touching [floor or wall v]?>
change y by (5)
end
If you want more jumping, more realistic gravity, etc. let me know
Last edited by MoreGamesNow (Aug. 16, 2014 07:10:51)
“Experience: that most brutal of teachers. But you learn, my God do you learn.”
- C.S. Lewis
- Dylanica
- Scratcher
54 posts
Collision with the ground
' You need to correct for both x and y collisions, ideally resolving one before the other takes place. Try something like this:when gf clicked
forever
if<key [right arrow v] pressed?>
change x by (5)
if<touching [floor or wall v]?>
change x by (-5)
end
end
if<key [left arrow v] pressed?>
change x by (-5)
if<touching [floor or wall v]?>
change x by (5)
end
end
change y by (-5)
if<touching [floor or wall v]?>
change y by (5)
end
If you want more jumping, more realistic gravity, etc. let me know
WOW thanks so much i can't believe it was so lol. And no thank you i have already figured out how to make realistic gravity: http://scratch.mit.edu/projects/25561779/
when I receive [Cookies v]
repeat until <(Cookies) = [ 0]>
play sound [Happy Noises v]
change [Cookies v] by (-1)
end
- Nightgaming71
- Scratcher
1 post
Collision with the ground
I´m just saying how to make gravity, do this:
FIRST CREATE A VARIABLE NAMED Y VELOCITY
FIRST CREATE A VARIABLE NAMED Y VELOCITY
when green flag clicked
go to x: (-142) y: (-33)
forever
change y by (Y VELOCITY)
set [Y VELOCITY v] to ((Y VELOCITY) * (.8))
if <touching color [#d0d60c] ?> then
set [Y VELOCITY v] to ((Y VELOCITY) * (-0.8))
else
change [Y VELOCITY v] by (-3)
end
Last edited by Nightgaming71 (Sept. 21, 2021 02:06:18)
- s3an-1234
- Scratcher
16 posts
Collision with the ground
when green flag clickedit is that easy
forever
if <not <touching [ground] ?>> then
repeat until <touching [ground] ?>
change y by (-3)
end
end
end
Last edited by s3an-1234 (Sept. 28, 2021 01:35:03)
- griefercube
- Scratcher
500+ posts
Collision with the ground
Don’t necropost, this is old.
sometimes, you just have to change a way of thinking to solve a problem. -griefercube
|other projects■how I made the banner■animated thumbnails?■i’m on wiki!■Cubey Mines|
|other projects■how I made the banner■animated thumbnails?■i’m on wiki!■Cubey Mines|
Last edited by griefercube (32th Undecimber, XXXX)
https://turbowarp.org/563693837/editor (something i did a while back don’t worry it’s for the banner)
list of working bbcodes:
[color=]
[scratchblocks]
[url=]
[img]
[center]
[code]
[code=]
[list]
[quote]
[b]
[i]
[u]
[s]
[big]
[small]
[p]
[wiki]
[google]
- Discussion Forums
- » Help with Scripts
- » Collision with the ground