Idk why my player keeps sinking

id: 747980

category: Help with Scripts

posts: 10

I was working on my runner game ( https://scratch.mit.edu/projects/983505725/ ) but the player kept sinking idk why this is happening.
deck26 deck26 loading
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.

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 BigNate469 loading
Get rid of the
when green flag clicked
forever
if <(y position) > [-37]> then
set y to (-37)
end
end
And change the
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.
Coding3dnow Coding3dnow loading
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
SpyCoderX SpyCoderX loading

BigNate469 wrote:

Get rid of the
when green flag clicked
forever
if <(y position) > [-37]> then
set y to (-37)
end
end
And change the
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.
I agree.

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 clicked
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
with
when green flag clicked
set [Y velocity v] to (0)
forever
if <touching [ground v]?> then
get out of ground ::custom
end
end
Hey spycoder I tried what you said but now my guy is floating
SpyCoderX SpyCoderX loading

ITSCraftyMinded14 wrote:

https://scratch.mit.edu/projects/983505725/editor/
I fixed up the player sprite (on my alt):
fixed version
How do I get a new signature?