• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

I need a script to fly my jetpack full of stamina.

K

Keith

Guest
I'm working on my capstone game and it's due at the end of the month. I want my character to fly with the jetpack he has on with how much stamina he has. Do you have a script for that? I am rushing to get everything this game needs and it needs to be done as soon as possible.
 

ophelius

Member
Do you know anything about how vectors work? Would you be able to make a lunar lander-type game if you wanted to? I'm just trying to understand your skill level because understanding how vectors work will make it easier to design more realistic jetpack physics.
 
K

Keith

Guest
Do you know anything about how vectors work? Would you be able to make a lunar lander-type game if you wanted to? I'm just trying to understand your skill level because understanding how vectors work will make it easier to design more realistic jetpack physics.
I am making a 8-bit style game in code where a spaceman shoots down robots and the sprite I made of him equips a jetpack. I made it in the Sprite Editor. I am a beginner at this and don't know how I can make my spaceman with the jetpack fly. Also the jetpack is powered with stamina so if there's no more stamina, he falls and can't fly until he finds fuel which is supposed to refill stamina.
 

FrostyCat

Redemption Seeker
This is just like jumping and moving put together, but with minor differences:
  • You subtract the vertical speed gradually when the jetpack key is held, instead of setting it straight to a negative value like when the jump key is tapped.
  • You subtract from your stamina variable when the jetpack key is held, instead of from x like when the left key is held.
  • You skip these jetpack key effects when your stamina is 0 or less or if the jetpack is not enabled.
Pretty easy if you have been doing your homework. If you have a platformer engine going already and you didn't just plagiarize it, this could done with existing knowledge in half an hour tops.
 

ophelius

Member
I am making a 8-bit style game in code where a spaceman shoots down robots and the sprite I made of him equips a jetpack. I made it in the Sprite Editor. I am a beginner at this and don't know how I can make my spaceman with the jetpack fly. Also the jetpack is powered with stamina so if there's no more stamina, he falls and can't fly until he finds fuel which is supposed to refill stamina.
What have you got so far in terms of code? Or is this a project you expect someone will write for you or hand you a script so you can meet your deadline?

To start you'll need 3 types of variables for your physics: gravity which is a constant, your x and y velocity, and your x and y position in space. The gravity adds a bit to your y velocity each frame, your positions change over time by the velocity magnitudes. Enabling your jetpack subtracts more from your y velocity than gravity adds, making you fly. Your x velocity is probably constant to the right.

Edit: You'll also need a jetpack acceleration variable, a reverse gravity so to speak, which subtracts that magnitude from your y velocity every frame when the jetpack is enabled.

But let us know what code you've written and we can help if you get stuck
 
Last edited:
K

Keith

Guest
What have you got so far in terms of code? Or is this a project you expect someone will write for you or hand you a script so you can meet your deadline?

To start you'll need 3 types of variables for your physics: gravity which is a constant, your x and y velocity, and your x and y position in space. The gravity adds a bit to your y velocity each frame, your positions change over time by the velocity magnitudes. Enabling your jetpack subtracts more from your y velocity than gravity adds, making you fly. Your x velocity is probably constant to the right.

Edit: You'll also need a jetpack acceleration variable, a reverse gravity so to speak, which subtracts that magnitude from your y velocity every frame when the jetpack is enabled.

But let us know what code you've written and we can help if you get stuck
This is the code I've started working on:
//jetpack
var move = key_right - key_left;

hsp = move * walksp;

vsp = vsp + grv;

if (place_meeting(x,y+1,oWall)) && (jetpack_trigger)
{
vsp = -jumpsp
}

It's the same as the "calculate movement" script, but I want my jetpack to fly until it's out of stamina. Solution?
 

ophelius

Member
Ok, so you'll need a variable for that, call is Stamina. Start with an amount like 1000 in the Create event of your player, and reduce it by 1 every frame only while you're in the air. Make it so you can't use your jetpack if Stamina == 0.

And you don't need to encapsulate each conditions seperately in an if statement, you can simply have: if ( place_meeting(x,y+1,oWall) && jetpack_trigger)
 
K

Keith

Guest
Ok, so you'll need a variable for that, call is Stamina. Start with an amount like 1000 in the Create event of your player, and reduce it by 1 every frame only while you're in the air. Make it so you can't use your jetpack if Stamina == 0.

And you don't need to encapsulate each conditions seperately in an if statement, you can simply have: if ( place_meeting(x,y+1,oWall) && jetpack_trigger)
This is my code so far based on your advice:
//jetpack
var move = key_right - key_left;

hsp = move * walksp;

vsp = vsp + grv;

if (place_meeting(x,y+1,oWall) && jetpack_trigger)
{
vsp = -jumpsp
stamina = -1;
if (stamina == 0)
}
What should I add to it?
 

ophelius

Member
Ok, this shows me that you don't have any programming fundamentals down yet, plus I don't think you understand the concepts I was explaining.
You should go learn about conditional statements and how if statements work(if (stamina == 0) is incomplete). You really also have to understand basic movement physics.
I think this may be beyond your comprehension for now, and without studying some basics first, there's no way you'll meet your deadline. If you don't want to learn and just want someone else's code, then I can't help you my friend.
 

FrostyCat

Redemption Seeker
This is my code so far based on your advice:
//jetpack
var move = key_right - key_left;

hsp = move * walksp;

vsp = vsp + grv;

if (place_meeting(x,y+1,oWall) && jetpack_trigger)
{
vsp = -jumpsp
stamina = -1;
if (stamina == 0)
}
What should I add to it?
Do you know the difference between stamina = -1; and stamina -= 1;? Or what the && does and why it should be used to join your stamina == 0 check?

Read up on how basic GML works before you proceed any further, particularly assignments, expressions and control structures. Your project is doomed if you don't learn this.
 
Top