Page 1 of 1

How to do a velocity jump -[Tutorial]-

PostPosted: Tue Jun 29, 2010 3:15 pm
by Hblade
Do a velocity jump
      by Hblade
Ever want to do a velocity jump, where you jump higher the longer you hold down the jump button? Well now you can! Lets get started shall we? use the graphics provided in the download link for this tutorial.

    Download
        Art.zip
        (690 Bytes) Downloaded 1285 times

        Art.rar
        (547 Bytes) Downloaded 950 times


Alright, first thing's first. Set your background color to
    Red: 83
    Green: 103
    Blue: 146
              Screenshot
              S1.JPG


This is so we can actually see our character, and thus making it easier on our eyes :P Good, now that you have the art set downloaded, lets start :D First, make your player. You can see through him, but thats okay. Now that you made him, go to draw actor - put this code in.
Code: Select all
if (yvelocity<4)
{
    yvelocity+=.08;
}

This will limit his falling speed. Now that you have that add your Tile actor, and draw some tiles! :D
              Screenshot
              s2.JPG


Now add a collision, any physical response will do, no need for fancy stuff since your just learning how to do a velocity jump :D. Now that you added a collision effect, you need to make hum jump! For now lets do a single jump. make a variable called cjump
              Screenshot
              s3.JPG

Now that you made that variable, make a keydown Event.
    •Key Down
      •Z
      •Script Editor
      Code: Select all
      if (cjump == 0)
      {
          yvelocity = -9;
          cjump = 1;
      }

Now, go back to your Draw Actor script, and add this to it:
Code: Select all
if (yvelocity>=1)
{
    cjump = 1;
}

This means that when you start to actually fall, the character wont be able to jump in the middle of the air that way you can avoid issues such as you walk off the edge of a cliff and your still able to jump. Since our yvelocity is adding by .8 each time, its good to have it actually say if its greater thatn or equal to 1, that way it wont glitch and keep you unable to jump even if on the ground. This happens as a result of Draw Actor trying to constantly add .8 to the falling speed, which is making yvelocity spike from 0 to .8 and the physical response stops the character so you dont notice it.

Re: How to do a velocity jump -[Tutorial]-

PostPosted: Tue Jun 29, 2010 4:07 pm
by Hblade
Do a velocity jump
      by Hblade
        Part 2

Part 2, limiting the jump

Now make a collision event with the tiles
    •Collision
      •Top Side of tiles
      •Script Editor
      Code: Select all
      cjump = 0;


Good, your almost done! :D Now, last but not least, make a key up event.
    •Key Up
      •Z
      •Script Editor
      Code: Select all
      if (cjump == 1)
      {
          yvelocity = yvelocity/2;
          cjump = 2;
      }

Now test it out! :D Hold down the Z button for a longer jump, or tap it for a smaller jump.

Now for the jump animation
Go back to you Draw Actor once again, and add this in it
Code: Select all
if (yvelocity>=2)
{
    ChangeAnimation("Event Actor", "dude_jump", FORWARD);
}

Your draw actor code should now look like this:
Code: Select all
if(yvelocity<4)
{
    yvelocity+=.8;
}
if (yvelocity>=1)
{
    cjump = 1;
}
if (yvelocity>=2)
{
    ChangeAnimation("Event Actor", "dude_jump", FORWARD);
}


Now go to the script editor of your collision - top side of tiles, and add this
Code: Select all
ChangeAnimation("Event Actor", "dude", FORWARD);


Now last but not least, we make the animation change when he jumps, so go to your key down Z and put this in between the if statement
Code: Select all
ChangeAnimation("Event Actor", "dude_jump", FORWARD);


Its complete :D!

Download and test it for yourself if you'd like. Use the arrow keys to move in this demo and Z to jump. If this was too complicated, please let me know right away.
                    Demo.zip
                    (2.99 KiB) Downloaded 993 times

                    Demo.rar
                    (2.63 KiB) Downloaded 750 times


Re: How to do a velocity jump -[Tutorial]-

PostPosted: Tue Jun 29, 2010 7:54 pm
by DST
good job noticing the canjump enable on the ground vs. speed thing.

Re: How to do a velocity jump -[Tutorial]-

PostPosted: Tue Jun 29, 2010 8:02 pm
by Hblade
I think it was you that told me that, or was it Skydereign? :/

Re: How to do a velocity jump -[Tutorial]-

PostPosted: Wed Jun 30, 2010 2:54 am
by Bee-Ant
Excellent tutorials...
Completed with screenshot and demo, very nice :D

Re: How to do a velocity jump -[Tutorial]-

PostPosted: Wed Jun 30, 2010 4:50 am
by Hblade
Thanks ^.^

Re: How to do a velocity jump -[Tutorial]-

PostPosted: Sat Jul 24, 2010 4:50 am
by Toasterman
Very useful! Thanks!
This clears up issues I'd been pretty much been stumped with! :D

Re: How to do a velocity jump -[Tutorial]-

PostPosted: Thu Dec 09, 2010 8:38 pm
by Orlando911
thank you for the explanation,

I got confused, for the change intimation when the player jump,

just explain this to me plz,

what I know, I have to picture of the player, when playerRight, and PlayerLeft,

I used the playerRight, in the beginning , then when I move it to the left, I want to show the PlayerLeft ,

Re: How to do a velocity jump -[Tutorial]-

PostPosted: Thu Dec 09, 2010 11:39 pm
by skydereign
There is a function called ChangeAnimation(). You have to use this on the event that moves the player. These questions are pretty basic, you really should check out the built in tutorials and the tutorials section. They'll give you enough grounding to learn effectively from the forum.

Re: How to do a velocity jump -[Tutorial]-

PostPosted: Fri Dec 10, 2010 8:16 pm
by Orlando911
thank u , I got it,

everything clear in the tutorial in the product ,

Re: How to do a velocity jump -[Tutorial]-

PostPosted: Wed Aug 03, 2011 3:23 pm
by happyjustbecause
I know this is an old tutorial, but I'm new and trying to get the hang of everything. I got the velocity jump to work, but I'm not sure how to implement both left and right jumping animations . But I had my animation changing when I was walking left and right before, but now it won't. And I'm not completely sure how to do the script editor to allow both animation changes. :mrgreen: :?:

I'm attaching my game in hope of someone checking it out and seeing what is wrong with the animation of walking. I can see it is still there, and when I jump and mess around with the arrowkeys it will occasionally switch to the walking animation. So anyways, any help of this would be greatly appreciated. I'm still learning the ropes, but I hope to get a grasp on the program! I will give a point to anyone that helps if that encourages them at all.

Re: How to do a velocity jump -[Tutorial]-

PostPosted: Wed Aug 03, 2011 6:29 pm
by Hblade
OH! Change "FORWARD" in the change animation to "NO_CHANGE"

Re: How to do a velocity jump -[Tutorial]-

PostPosted: Thu Aug 04, 2011 10:02 pm
by happyjustbecause
Ahhh, Thank you, I was thinking it was probably just something simple. :D

Thanks Again for the tutorial in the first place, and for the added help!

Re: How to do a velocity jump -[Tutorial]-

PostPosted: Sat Aug 06, 2011 3:23 am
by Hblade
lol your welcome. did it help? o3o

Re: How to do a velocity jump -[Tutorial]-

PostPosted: Mon Feb 17, 2014 6:46 pm
by marcus
Hello,

I think this script is awesome, thanks a lot Hblade! But I trying to do a little improve/modification and don't know how to do it: I wish the character gain speed as it falls, especially if you are jumping from a higher platform - it's possible?

I posting my game for example (it is in the very begining, no sprite animations there); use the arrows to move left and right, spacebar to jump. There's some glitches with the colision on plataforms too, but I'm sure there's nothing to do with the script of this thread - but if someone can help, it will be nice! The glitches is: just walk to the right and the character will "climb" the plataforms, no need to jump; if you stop near the edge, the character will move until he falls; and the character can be stuck in the plataform by his (big and weird) hair.



Thanks for the attention and sorry for the bad english,
=]

UPDATE

I think I make it work! Probably it isn't the better code, but is working. First, I declared a variable name tempy, then I added this to Player -> Draw Actor

Code: Select all
if <yvelocity>=0>
{
    tempy=yvelocity;
}
// if the character is ascending, the yvelocity is stored in the tempy variable

if <tempy<=yvelocity>
{
    yvelocity+=0.5;
}
// if your yvelocity starts to decline (the script check this comparing the stored yvelocity with the actual yvelocity), you get down more fast (increasing your yvelocity)
// the 0.5 is a trial-and-error that works best for my case, you should experiment with little increments


=]