Doc
Member
Hello all! first off, I'll apologize in advance as this very likely has been covered before, but I am two days in and have a super limited understanding of GML and programming in general.
So I have a working state machine up and running. obj horizontal movement is working fine, as well as a timer to move the obj into the next state:
My problem begins when I move into my "jumping state":
A lot of this has been commented out and changed due to frustration lol. Here is the obj create event code just in case:
I've tried a few different IF statements, working with vspeed, gravity, and a combination of the two. The best I can manage is jerky hops of only a few pixels, or the obj flies/floats of the screen.
What I would like to have happen is this:
When the obj enters the jumping state, it immediately jumps (speed builds up gradually to the peak, then speeds build on the descent, but slower), then if obj hits the ground it moves back into the ground state. If it collides with another object, it would grab a new vspeed/gravity off of them and repeat.
Thanks in advance for any help/correction/guidance on this problem, and if any of you need an extra set of eyes on art related problems let me know.
So I have a working state machine up and running. obj horizontal movement is working fine, as well as a timer to move the obj into the next state:
Code:
script_execute(scr_player_move);
//if the jump timer triggers, reset it
//so it can trigger again as long as on the ground
if ((jumptimer <= 0) && vspeed == 0)
{
jumptimer = 70;
}
//check and force collision to the ground
if (!place_meeting(x, y +1, obj_floor))
{
vspeed = 1;
}
else
{
vspeed = 0;
}
//alarm jump
if (jumptimer && !--jumptimer)
{
state = states.air;
}
Code:
script_execute(scr_player_move);
//jump setting
for (--vspeed; position_empty(x, y + 1); vspeed = 2)
{
--vspeed;
}
//enemy collision
/*
//ground collision returns to ground state
if (!place_meeting(x, y +2, obj_floor))
{
vspeed = 5;
}
//else if (!place_meeting(x, y +1, obj_floor))
{
state = states.ground;
}
Code:
//movement speed used for left right movement
spd = 5;
//jump and gravity speed
jmpspd = 5;
grvspd = 2;
// zero out object movement
hspeed = 0;
vspeed = 0;
//used to stop left and right movement
friction = 0.25;
//triggers return to air state from ground
jumptimer = 20;
//sets initial player state
state = states.ground;
I've tried a few different IF statements, working with vspeed, gravity, and a combination of the two. The best I can manage is jerky hops of only a few pixels, or the obj flies/floats of the screen.
What I would like to have happen is this:
When the obj enters the jumping state, it immediately jumps (speed builds up gradually to the peak, then speeds build on the descent, but slower), then if obj hits the ground it moves back into the ground state. If it collides with another object, it would grab a new vspeed/gravity off of them and repeat.
Essentially the game I'm trying to make is built around jumping on enemies. I figured I would start with a simple concept in the hopes of having a realistic to finish game. I have a pretty big background in art, so I want to see if I can complete a small game top to bottom, which will also let me know if I like the process. This is day two, and except for this headache, I like it so far
Thanks in advance for any help/correction/guidance on this problem, and if any of you need an extra set of eyes on art related problems let me know.