This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2010-08-17 23:12:16

Locomule
Scratcher
Registered: 2009-08-24
Posts: 500+

A simple velocity type jump without using velocity

Here is a method that will give you a velocity type jump but doesn't actually use velocity. It is currently set to do a fairly fast jump. This is a very simple jump that does not work for platforms because it will put the sprite back on the same ground level that it started out jumping from. But it is a great jumping method for something like a side-scrolling player vs. cpu fighting game (Mortal Kombat, Street Fighter, etc)

http://a.imageshack.us/img13/2217/scriptk.gif

This is a small script but it does a lot of cool things...
1) the first purple block sets the sprite to it's "bend" costume which looks like it is bending down and getting ready to jump.

2) the WAIT block holds that pose just long enough for it to be seen but not so long as to slow down the entire jump movement

3) SET JUMPING TO YES- I use the variable "jumping" in other parts of the script to make sure that the player cannot hit other keys and do something else while the sprite is still jumping

4) SET JUMP TO 0- The variable "jump" is going to be looped and increased in a range from 0 to 170 in the following REPEAT block loop

5) SWITCH TO COSTUME JUMP- The sprite has already bent down, now it will switch to it's "in the air" leaping-type look

6) REPEAT 17 (and the 2 blocks inside it)- This loop increases the "jump" variable by 10 every time it repeats as well as adjusting the sprite's Y position. The changing Y (the actual jumping action) is figured by getting the Cosine amount of the variable "jump" every loop repetition

7) SWITCH TO COSTUME WALK- Now that the actual jump is over, the sprite is back on the ground so we switch it to it's 'just standing there' look. You could instead make a 'landing' costume or even re-use the "bend" costume if you wanted. But I needed a fast jump and this version looks fine for my purposes

8) SET JUMPING TO NO- And finally, we are resetting that "jumping" variable so that the player can once again hit keys and move however they want to


You can adjust the height of the jump by adjusting the "30" amount in the CHANGE Y BY COS OF JUMP * 30 block. A higher amount will result in a bigger jump, while a smaller amount will decrease the jump height.

You can also adjust the speed of the jump by changing both the number of repeats and the CHANGE JUMP BY 10 amount. For instance..
change the 17 to 35 and the 10 to 5 will give you a slower, smoother jump.

You have to change both numbers a certain way to ensure that the sprite lands at the same ground level that it took off from. See if you can figure out how that works  smile  And if you can't, click the sprite's Y position variable in the Motion blocks so that it stays visible on the screen. Remember what it is, jump, and see what it stops at. Adjust one of the amounts until it lands correctly at the same Y value that it started at.

Happy jumping!

Last edited by Locomule (2010-08-18 01:40:05)


aka Pain from DragonSpires, Delrith Online, BotBattle, Urban Dead etc etc lol

Offline

 

#2 2010-08-18 00:56:11

Sunrise-Moon
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: A simple velocity type jump without using velocity

Another well-written Locomule tutorial! I only wish I could press 'love-it' on threads!


http://i1067.photobucket.com/albums/u427/HulKDzN/RebornBlade.png

Offline

 

#3 2010-08-18 01:47:58

Locomule
Scratcher
Registered: 2009-08-24
Posts: 500+

Re: A simple velocity type jump without using velocity

You are too kind! Honestly, I intended it as a alternative to colorfusion's great post here but after i made it I realized it totally did not work for 17588's needs. Whoops. I may need to not try to help anyone after 11:00 pm lol.


aka Pain from DragonSpires, Delrith Online, BotBattle, Urban Dead etc etc lol

Offline

 

#4 2010-08-18 02:13:21

Jonathanpb
Scratcher
Registered: 2008-07-25
Posts: 1000+

Re: A simple velocity type jump without using velocity

It's a bit like velocity... it still has the variable changing and the movement based on that variable.  tongue

Last edited by Jonathanpb (2010-08-18 02:13:41)


"Human beings... must have action; and they will make it if they cannot find it.
-Charlotte Brontë

Offline

 

#5 2010-08-18 08:14:10

laser100
Scratcher
Registered: 2009-12-04
Posts: 100+

Re: A simple velocity type jump without using velocity

Nice tutorial!  smile
But I prefer my own method.

Offline

 

#6 2010-08-18 08:43:40

Locomule
Scratcher
Registered: 2009-08-24
Posts: 500+

Re: A simple velocity type jump without using velocity

Lol, Jonathanpb, good point. When I say "velocity type jump" I really just mean in appearance. And by that I mean It starts moving fast as it goes up, slows as it reaches the peak of the jump, and then speeds back up on the way down.

And I kind of fibbed a little when I said it wasn't for platformers. It works pretty nicely in my platformer demo but I am using the much dreaded (lol) color sensing collision detection method. Try jumping up and down the hill, pretty cool, eh? I used a slightly more complicated method that mixes Sine on the X plane and Cosine on the Y plane to create a jump that goes sideways as well as up and down. I also experimented with putting the jump script into the Stage's blocks instead of the player sprite's scripts.

As with any routine, nothing is 'best', it depends on what you need in a particular project. I usually find myself mixing multiple methods in a single project. The latest update of my project includes a "spikebot" enemy that uses the "if sprite touching" method as well. He doesn't come out until you move to another map and wait a bit.

Last edited by Locomule (2010-08-18 10:06:40)


aka Pain from DragonSpires, Delrith Online, BotBattle, Urban Dead etc etc lol

Offline

 

#7 2010-08-18 11:41:52

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: A simple velocity type jump without using velocity

Impressive! Great way to make a nice arc. You could also add a repeat until c block instead of Repeat () if you wanted jumping on non flat ground.

Code:

Repeat until << jump = 170 > or < touching color ()>>
change jump by 10
change y by ((cos of jump) * 30)
End repeat

But you probably already figured that out.  tongue

EDIT: Never mind, I just read your last post.

Last edited by Harakou (2010-08-18 11:42:47)


http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/OZn2RD3.png&amp;link2=http://i.imgur.com/duzaGTB.png&amp;link3=http://i.imgur.com/CrDGvvZ.png&amp;link4=http://i.imgur.com/POEpQyZ.png&amp;link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

#8 2010-08-18 12:45:19

Locomule
Scratcher
Registered: 2009-08-24
Posts: 500+

Re: A simple velocity type jump without using velocity

No, you hit it on the money! In my platformer, I was 'faking' your idea by adding an additional +Y or -Y move after it landed depending on which way it faced. It worked ok but your way is much better, thanks Harakou!


aka Pain from DragonSpires, Delrith Online, BotBattle, Urban Dead etc etc lol

Offline

 

#9 2010-08-18 13:10:36

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: A simple velocity type jump without using velocity

Oh! Well, glad I could help then.


http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/OZn2RD3.png&amp;link2=http://i.imgur.com/duzaGTB.png&amp;link3=http://i.imgur.com/CrDGvvZ.png&amp;link4=http://i.imgur.com/POEpQyZ.png&amp;link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

Board footer