How to jump in RPG-style game?
#1
Posted 05 April 2012 - 11:09 PM
Help?
#2
Posted 06 April 2012 - 12:46 AM
Now, as for your question...
Jumping is completely dependent on the view of your game. An RPG is usually top-down, so I'll assume that's what yours is. In that case, "jumping" is not very well-defined. What should jumping do? Allow you to collide with dangers/holes without getting hurt? Pass through obstacles?
Since you didn't give much information about your game, nor about what jumping means in your game, the best I can say functionally is that when you jump, you should set a "jumping" variable to true. In the CREATE event, "jumping" should be initialized to false.
As for the visual aspect, it's easiest to just use a sinusoidal function (that is, sin or cos) to change the scale of the sprite. As it scales up, it looks like he's jumping higher, and as it scales down it looks like he's falling. When the scale reaches 1 again, he's landed, so that's when you'd set "jumping" to false.
For example (with a centered origin on your sprite!):
/* CREATE */
jumping = false;
jumpHeight = 0;
/* Jump key pressed event */
jumping = true;
jumpHeight = 0;
/* STEP event */
jumpHeight += 1;
image_xscale = 1 + 0.5 * sin(jumpHeight);
image_yscale = image_xscale;
if (sin(jumpHeight) <= 0) { jumping=false; image_xscale=0; image_yscale=0; }The 0.5 can be changed to anything; it's the maximum addition to the scaling. At 0.5, the sprite will be scaled to 1.5x at max height. If you made it 1 instead, for instance, max height would scale it to 2x.
-IMP
#3
Posted 06 April 2012 - 03:11 AM
For future reference, questions about programming that are not specific to one version of Game Maker should be in the Novice & Intermediate Users forum. I've moved it for you this time, but in the future a mod might just close it, so be careful
.
Now, as for your question...
Jumping is completely dependent on the view of your game. An RPG is usually top-down, so I'll assume that's what yours is. In that case, "jumping" is not very well-defined. What should jumping do? Allow you to collide with dangers/holes without getting hurt? Pass through obstacles?
Since you didn't give much information about your game, nor about what jumping means in your game, the best I can say functionally is that when you jump, you should set a "jumping" variable to true. In the CREATE event, "jumping" should be initialized to false.
As for the visual aspect, it's easiest to just use a sinusoidal function (that is, sin or cos) to change the scale of the sprite. As it scales up, it looks like he's jumping higher, and as it scales down it looks like he's falling. When the scale reaches 1 again, he's landed, so that's when you'd set "jumping" to false.
For example (with a centered origin on your sprite!):/* CREATE */ jumping = false; jumpHeight = 0; /* Jump key pressed event */ jumping = true; jumpHeight = 0; /* STEP event */ jumpHeight += 1; image_xscale = 1 + 0.5 * sin(jumpHeight); image_yscale = image_xscale; if (sin(jumpHeight) <= 0) { jumping=false; image_xscale=0; image_yscale=0; }
The 0.5 can be changed to anything; it's the maximum addition to the scaling. At 0.5, the sprite will be scaled to 1.5x at max height. If you made it 1 instead, for instance, max height would scale it to 2x.
-IMP
Exactly what he said, the basics of creating a jumping effect all depend on your point of view. Most of the time you will be using gravity and a bunch of other stuff, there are PLENTY of tutorials out there.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











