G
gabrielcamargo
Guest
Newbie here. As the title says, how to make the player only jump when the animation is played? And sorry for my bad english, but even so I think you can understand.
if (image_index == 4) {
ySpeed = -4;
}
Are you able to post the code you have so far?Newbie here. As the title says, how to make the player only jump when the animation is played? And sorry for my bad english, but even so I think you can understand.
vspeed += grv;
// vspeed is a variable that holds the current speed your object is travelling at in the vertical direction.
// and grv is a variable that holds your gravitational constant 0.4 for example.
// Check for event that triggers a jump state
if (button_pressed) vspeed = -jump_speed // where jump_speed is a variable that holds the speed you want you char to jump at
// Collision code goes here and if true move the player object to be up tight to the collision object and then set the vspeed to zero.
if (place_meeting(x, y + vspeed, o_wall)) { // Checks for a collision in the direction of vspeed
while(!place_meeting(x, y + sign(vspeed), o_wall)) { // If there has been a collision move the player up tight to the object it has collided with.
y += sign(vspeed);
}
vspeed = 0; // Collision forces the player to stop.
}
// Then once gravity, jump and collisions have been checked and dealt with you add the vspeed value to the y position.
y += vspeed;
thank you guys, after researching a lot I arrived at the result in a very simple way. when the player presses the space key the animation is played, when he releases it (through the key up event), the player jumps!Are you able to post the code you have so far?
As @Octtopus_Tophat says a jump would normally be triggered by a button press but there are also in game events that may cause this as well, a spring pad or an explosion for example but their point remains the same, an external event triggers the player to jump and then you set an animation for that event.
Normally you would have some simple gravity system in a game that pulls the objects to the ground. such as ...
There are more checks and events that need to be dealt with but this is basically a simple jump and gravity system that allows you to create a jumping system.GML:vspeed += grv; // vspeed is a variable that holds the current speed your object is travelling at in the vertical direction. // and grv is a variable that holds your gravitational constant 0.4 for example. // Check for event that triggers a jump state if (button_pressed) vspeed = -jump_speed // where jump_speed is a variable that holds the speed you want you char to jump at // Collision code goes here and if true move the player object to be up tight to the collision object and then set the vspeed to zero. if (place_meeting(x, y + vspeed, o_wall)) { // Checks for a collision in the direction of vspeed while(!place_meeting(x, y + sign(vspeed), o_wall)) { // If there has been a collision move the player up tight to the object it has collided with. y += sign(vspeed); } vspeed = 0; // Collision forces the player to stop. } // Then once gravity, jump and collisions have been checked and dealt with you add the vspeed value to the y position. y += vspeed;