Discuss Scratch

MapleTree_
Scratcher
6 posts

How do I make my character jump smoothly until it reaches a certain y pos?

I'm making a platformer, I've made the jumping code, but my old code:

repeat (10)
change y by (10)

end
repeat (10)
change y by (-10)

end

made it so that when my character jumped off a platform, the character landed on the same y pos as the platform. So I made a NEW code so that it would be able to stop jumping at a certain y pos:

repeat (10)
change y by (10)


end
repeat until <touching color [#08d046] ?>
change y by (-1)
end

But as you can guess, it wasn't that smooth. So I have to ask:

How do I make my character jump smoothly until it reaches a certain y pos?

Last edited by MapleTree_ (Jan. 6, 2021 18:27:04)

ScratchCatHELLO
Scratcher
1000+ posts

How do I make my character jump smoothly until it reaches a certain y pos?

You should try using
<(y position) = [123]> //replace 123 with the y pos that you want it to stop at.
Instead of
<touching color [#0a77e3] ?>

Also, this belongs in Help with Scripts, not Questions about Scratch. Requesting to be moved.
MapleTree_
Scratcher
6 posts

How do I make my character jump smoothly until it reaches a certain y pos?

ScratchCatHELLO wrote:

You should try using
<(y position) = [123]> //replace 123 with the y pos that you want it to stop at.
Instead of
<touching color [#0a77e3] ?>

Also, this belongs in Help with Scripts, not Questions about Scratch. Requesting to be moved.
But ScratchCatHELLO, I need a way to calculate how much my character should move downwards. I can repost in Help with Scripts btw.
xXRedTheCoderXx
Scratcher
1000+ posts

How do I make my character jump smoothly until it reaches a certain y pos?

Try this:
if <touching color [#08d046]?> then
set [Y velocity v] to [5]
change y by (Y velocity)
repeat until <touching color [#08d046]?>
change [Y velocity v] by (-1)
change y by (Y velocity)
end
end

Try messing around with the values to see what's best for your game. Maybe set Y velocity to 3, or 10 insead of 5. Or try having the Y velocity change by -3 or -5 instead of -1. Hope this helped.
portalpower
Scratcher
1000+ posts

How do I make my character jump smoothly until it reaches a certain y pos?

set [+y v] to (height)
repeat (height)
change y by (+y)
change [+y v] by (-1)
end
repeat until <touching color [#00ff00] ?>
change y by (+y)
change [+y v] by (-1)
end
MapleTree_
Scratcher
6 posts

How do I make my character jump smoothly until it reaches a certain y pos?

xXRedTheCoderXx wrote:

Try this:
if <touching color [#08d046]?> then
set [Y velocity v] to [5]
change y by (Y velocity)
repeat until <touching color [#08d046]?>
change [Y velocity v] by (-1)
change y by (Y velocity)
end
end

Try messing around with the values to see what's best for your game. Maybe set Y velocity to 3, or 10 insead of 5. Or try having the Y velocity change by -3 or -5 instead of -1. Hope this helped.
I don't use velocity in my game doe…
Klicky_Kitty
Scratcher
40 posts

How do I make my character jump smoothly until it reaches a certain y pos?

MapleTree_ wrote:

xXRedTheCoderXx wrote:

Try this:
if <touching color [#08d046]?> then
set [Y velocity v] to [5]
change y by (Y velocity)
repeat until <touching color [#08d046]?>
change [Y velocity v] by (-1)
change y by (Y velocity)
end
end

Try messing around with the values to see what's best for your game. Maybe set Y velocity to 3, or 10 insead of 5. Or try having the Y velocity change by -3 or -5 instead of -1. Hope this helped.
I don't use velocity in my game doe…
You should use velocity. If you don’t, then stick to the not smooth thing. It’s much glitchier and the variable helps a lot.
thesuperfuncoder
Scratcher
77 posts

How do I make my character jump smoothly until it reaches a certain y pos?

MapleTree_ wrote:

xXRedTheCoderXx wrote:

Try this:
if <touching color [#08d046]?> then
set [Y velocity v] to [5]
change y by (Y velocity)
repeat until <touching color [#08d046]?>
change [Y velocity v] by (-1)
change y by (Y velocity)
end
end

Try messing around with the values to see what's best for your game. Maybe set Y velocity to 3, or 10 insead of 5. Or try having the Y velocity change by -3 or -5 instead of -1. Hope this helped.
I don't use velocity in my game doe…
, also that should be if not touching color green

Last edited by thesuperfuncoder (Jan. 7, 2021 02:34:06)

keywastaken
New Scratcher
3 posts

How do I make my character jump smoothly until it reaches a certain y pos?

xXRedTheCoderXx wrote:

Try this:
if <touching color [#08d046]?> then
set [Y velocity v] to [5]
change y by (Y velocity)
repeat until <touching color [#08d046]?>
change [Y velocity v] by (-1)
change y by (Y velocity)
end
end

Try messing around with the values to see what's best for your game. Maybe set Y velocity to 3, or 10 insead of 5. Or try having the Y velocity change by -3 or -5 instead of -1. Hope this helped.

Sorry for necroposting, but how do I get my player character to jump while moving? When I pressed the jump button and the arrow keys at the same time, it just stopped and then jumped, then resumed moving. How do I fix this?

Last edited by keywastaken (Dec. 15, 2022 15:45:46)

Powered by DjangoBB