Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Idk why my player keeps sinking
- ITSCraftyMinded14
- Scratcher
16 posts
Idk why my player keeps sinking
I was working on my runner game ( https://scratch.mit.edu/projects/983505725/ ) but the player kept sinking idk why this is happening.
Hello, I'm Crafty! I'm an average Scratch programmer. I'm racing @johnthesussy to 100 followers! So plz follow me, It's a big help!
- deck26
- Scratcher
1000+ posts
Idk why my player keeps sinking
Too many green flag scripts with forever loops! Best practice is to ensure all starting conditions are set up and only then run game play scripts. One of your problems is that you never initialise YVelocity - try monitoring the value! You also allow YVelocity to get too big so it drops well into the hitbox before it stops moving.
Why do you start the player at y=-45 when you have a forever loop that will then change that to -37?
Those are the issues I found immediately. I do think your scripts are fighting each other to position the sprite and you have no idea what order they are running in. Getting more control of the order would be sensible.
when green flag clicked
broadcast [initialise v] and wait // sprites set positions, costumes variables etc
broadcast [ready v] // now game play can begin
Why do you start the player at y=-45 when you have a forever loop that will then change that to -37?
Those are the issues I found immediately. I do think your scripts are fighting each other to position the sprite and you have no idea what order they are running in. Getting more control of the order would be sensible.
- BigNate469
- Scratcher
1000+ posts
Idk why my player keeps sinking
Get rid of the
when green flag clickedAnd change the
forever
if <(y position) > [-37]> then
set y to (-37)
end
end
go to x: (-116) y: (-45)to
go to x: (-116) y: (idk, something higher than 0)Also, make it so that after the sprite hits the ground it gets pushed out of the ground- this can be a little tricky to program but it is worth it in the end.
Highlight any part of this signature and press ctrl+shift+down arrow to see the rest of it
foreverPlease read the list of Officially Rejected Suggestions before posting a suggestion for Scratch! 100th post
if <person asks [what's a signature] :: sensing> then
Redirect to [https://en.scratch-wiki.info/wiki/Signature] :: motion
end
end
This signature is designed to be as helpful as possible.
View all of the topics you've posted in:
https://scratch.mit.edu/discuss/search/?action=show_user&show_as=topics
View all of your posts:
https://scratch.mit.edu/discuss/search/?action=show_user&show_as=posts
Forum tips:
Don't post in topics where the latest post is over ~2 months old, unless you have something critical to add. Especially in topics that are several years old- it isn't helpful, and is known as necroposting.
Don't post unrelated things in topics, including questions of your own. Make a new topic for your questions.
You can use the
[color=color name or hexadecimal value here] and [/color]
Lesser-known Scratch URLs:
https://scratch.mit.edu/projects/PROJECT ID HERE/remixtree (replace “PROJECT ID HERE” with project id number. Shows all the remixes of the project, and the remixes of those projects, and the remixes of those projects, and so on, as a chart. Link currently redirects to one of my projects)
View a larger list at: https://scratch.mit.edu/discuss/topic/542480/
Why @Paddle2See's responses are so often identical: https://scratch.mit.edu/discuss/topic/762351/
1000th post
- Coding3dnow
- Scratcher
16 posts
Idk why my player keeps sinking
ok so i went in your project and with you hitbox script you need to set the velocity to zero when y is below -32
scratch = 3d = true
- SpyCoderX
- Scratcher
500+ posts
Idk why my player keeps sinking
I agree. Get rid of thewhen green flag clickedAnd change the
forever
if <(y position) > [-37]> then
set y to (-37)
end
endgo to x: (-116) y: (-45)togo to x: (-116) y: (idk, something higher than 0)Also, make it so that after the sprite hits the ground it gets pushed out of the ground- this can be a little tricky to program but it is worth it in the end.
The “after the sprite hits the ground it gets pushed out of the ground” is basically this:
define get out of ground
repeat until <not <touching [ground v]?>>
change y by (1) //Move 1 pixel up until you're out of the ground.
end
set [Y velocity v] to [0] //You're on the ground, so you would have 0 vertical velocity.
You would want to replace the script you have:
when green flag clickedwith
forever
if <not <touching [ground v]?>> then
repeat until <touching [ground v]?>
change [Y velocity v] by (-1)
change y by (Y velocity)
end
set [Y velocity v] to (0)
end
end
when green flag clicked
set [Y velocity v] to (0)
forever
if <touching [ground v]?> then
get out of ground ::custom
end
end
Last edited by SpyCoderX (March 15, 2024 16:56:02)
New game! (link)
Have a good day/night!
\(-_-) ::#00AAAA //This is crypto. He protects my signature from the evil kumquats!Programming is a very powerful skill. As are critical thinking and hard work.
- SpyCoderX
- ITSCraftyMinded14
- Scratcher
16 posts
Idk why my player keeps sinking
Hey spycoder I tried what you said but now my guy is floating
Hello, I'm Crafty! I'm an average Scratch programmer. I'm racing @johnthesussy to 100 followers! So plz follow me, It's a big help!
- ITSCraftyMinded14
- Scratcher
16 posts
Idk why my player keeps sinking
Hello, I'm Crafty! I'm an average Scratch programmer. I'm racing @johnthesussy to 100 followers! So plz follow me, It's a big help!
- SpyCoderX
- Scratcher
500+ posts
Idk why my player keeps sinking
https://scratch.mit.edu/projects/983505725/editor/I fixed up the player sprite (on my alt):
fixed version
New game! (link)
Have a good day/night!
\(-_-) ::#00AAAA //This is crypto. He protects my signature from the evil kumquats!Programming is a very powerful skill. As are critical thinking and hard work.
- SpyCoderX
- ITSCraftyMinded14
- Scratcher
16 posts
Idk why my player keeps sinking
Thanks
Hello, I'm Crafty! I'm an average Scratch programmer. I'm racing @johnthesussy to 100 followers! So plz follow me, It's a big help!
- ITSCraftyMinded14
- Scratcher
16 posts
Idk why my player keeps sinking
How do I get a new signature?
Hello, I'm Crafty! I'm an average Scratch programmer. I'm racing @johnthesussy to 100 followers! So plz follow me, It's a big help!
- Discussion Forums
- » Help with Scripts
- » Idk why my player keeps sinking