Discuss Scratch

_The_Artist_
Scratcher
28 posts

Making A Sprite Jump Smoothly

Hi! I'm making a platformer for the first time, and I'm trying to make my sprite jump smoothly. I've looked at different forums and stuff, but I'm having a hard time making my sprite jump diagonally and smooth. I don't really want to take anything from anyone's project. Any code that might help? I want to keep it simple. Thanks!
mstone326
Scratcher
1000+ posts

Making A Sprite Jump Smoothly

THis is a good place to start. It covers everything for a platformer. Just take your time going through it. Otherwise, we'll have to see what you have so far and try to adapt a jump script for you.

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


Edit:
I had a simple jump project in my forum help studio but best to follow the above tutorial I linked.
https://scratch.mit.edu/projects/150519918/

Last edited by mstone326 (Jan. 2, 2018 01:56:11)

elias_the_dank
New Scratcher
9 posts

Making A Sprite Jump Smoothly

Here is a script that will make your sprite jump smoothly:

whenclickedsetjump heightto15 Change this value depending on how high you want the sprite to jumpforeverifkeyspacepressed?thensetjump velocitytojumpheightrepeatuntiljumpvelocity=0changeybyjumpvelocitychangejump velocityby-1repeatuntiljumpvelocity=join-jumpheightchangejump velocityby-1changeybyjumpvelocity

…rather than just doing this:

whenclickedforeverifkeyspacepressed?thenglide.5secstox:xpositiony:yposition+15glide.5secstox:xpositiony:yposition-15

…which does not work well AT ALL. Hope this helps! Can't wait to see your project!
_The_Artist_
Scratcher
28 posts

Making A Sprite Jump Smoothly

elias_the_dank wrote:

Here is a script that will make your sprite jump smoothly:

whenclickedsetjump heightto15 Change this value depending on how high you want the sprite to jumpforeverifkeyspacepressed?thensetjump velocitytojumpheightrepeatuntiljumpvelocity=0changeybyjumpvelocitychangejump velocityby-1repeatuntiljumpvelocity=join-jumpheightchangejump velocityby-1changeybyjumpvelocity

…rather than just doing this:

whenclickedforeverifkeyspacepressed?thenglide.5secstox:xpositiony:yposition+15glide.5secstox:xpositiony:yposition-15

…which does not work well AT ALL. Hope this helps! Can't wait to see your project!
Thanks! I may use this in the future, but for right now I'm trying to keep the code fairly simple.
saodtheking
Scratcher
100+ posts

Making A Sprite Jump Smoothly

This is the simplest way i can think of

whenspacekeypressedsety velocityto15iftouchingGroundthenchangeybyyvelocityrepeatuntiltouchingGroundchangeybyyvelocitychangey velocityby-1sety velocitytoyvelocity*-1changeybyyvelocity
Miner3141
Scratcher
56 posts

Making A Sprite Jump Smoothly

_The_Artist_ wrote:

Hi! I'm making a platformer for the first time, and I'm trying to make my sprite jump smoothly.
whenclickedsetpowerto5repeat20changeybypowerchangepowerby-0.5iftouchinggroundifpower>0setpowerto0-powerrepeatuntilpower=0changeybypowerchangepowerby-0.5elsestopthis scriptoptionalforenemiesthatdetectjumping:broadcastjumped
If your head hits ground, you fall back down. If your feet hit ground, you stop jumping

Last edited by Miner3141 (Jan. 3, 2018 17:56:14)

Powered by DjangoBB