Help me with the jump?

BrolyDev

Member
Hola disculpa las molestias, tengo un problema serio con hacer que una variable funcione xD y me ayudes a resolver mi código?
aquí está mi código:
[CÓDIGO = gml]
Que quiero que no pueda saltar si está en el aire, solo cuando la velocidad vertical sea igual a 0

/// Saltar
// Animación
if vspeed = 0 {
image_index = 0;
}
if vspeed> = 1 {
image_speed = 0.25;
}
//Variable
if vspeed> = 25 {
Jump = falso;
}
if vspeed = 0 {
Saltar = verdadero;
}
// SALTAR
si Jump == true {
if keyboard_check (vk_space) {
vspeed = -10;
}
}
if Jump == false {
if keyboard_check (vk_space) {
vspeed = 0;
}
}
[/CÓDIGO]
Lo puse en el paso de inicio y también puse el evento de creación:
[CÓDIGO = gml]
/// Gravedad
if place_free (x, y) {
gravedad = 1;
}
demás {
gravedad = 0;
}
if vspeed> = 20 {vspeed = 20;}
//Variable
Saltar = verdadero
[/CÓDIGO]

ayúdame a arreglarlo?



NOCTURNE EDIT: título del tema editado para hacerlo un poco más descriptivo, y agregué algunos bloques de código para que el código sea más legible. Si desea obtener ayuda en el foro, ¡debe comenzar ayudándonos a comprender el problema! ¡Explique claramente cuál es el problema!
 
Last edited:

EvanSki

Raccoon Jam Host
And second
 

Joe Ellis

Member
The thing is, from looking at the code there's no way to tell what is going wrong\what isn't working how you want it to. The code will work without an error crash but it's obviously not working how you want. But you need to explain what the problem is. What you want to happen and what isn't happening\what's happening instead.
 

BrolyDev

Member
Setting gravity like this in the create event is probably not what you want, but I can't really decipher all that text formatted that way...
Gravity is not my real problem, the truth works quite well for me, what I ask for help is that I only jump when I touch the ground
 

BrolyDev

Member
[QUOTE = "Joe Ellis, publicación: 524035, miembro: 4559"]
The thing is, from looking at the code there's no way to tell what is going wrong\what isn't working how you want it to. The code will work without an error crash but it's obviously not working how you want. But you need to explain what the problem is. What you want to happen and what isn't happening\what's happening instead.
[/QUOTE]

Ok, sorry I'm new here in this community xD, what I need is for me to jump when the player hits the ground
 

FoxyOfJungle

Kazan Games
Your thread translated and formatted:
.
.
Hello sorry for the inconvenience, I have a serious problem with making a variable work xD and you help me solve my code?

Here is my code:
That I want it to not be able to jump if it is in the air, only when the vertical speed is equal to 0

GML:
/// JUMP
// Animation
if (vspeed == 0) {
    image_index = 0;
}

if (vspeed >= 1) {
    image_speed = 0.25;
}

if (vspeed >= 25) {
    Jump = false;
}

if (vspeed == 0) {
    jump = true;
}

// Jump
if (Jump) {
    if keyboard_check(vk_space) {
        vspeed = -10;
    }
}

if (!Jump) {
    if keyboard_check(vk_space) {
        vspeed = 0;
    }
}

I put it in the step event and also put the create event:

GML:
/// Gravity
if place_free(x, y) {
    gravity = 1;
} else {
    gravity = 0;
}

if (vspeed >= 20) {
    vspeed = 20;
}

jump = true;
Help me fix it?
 

Nidoking

Member
A few things to watch for:

Jump and jump are two different variables. Sometimes, you use jump, and sometimes, you use Jump. These are not the same.

You're only looking at vspeed to determine whether or not you can jump (or Jump). vspeed will be zero when you're on the ground (hopefully), but also at the peak of the jump. And you don't set Jump (or jump) to false until vspeed is greater than 25. Two problems with that: First, there's a very wide gap between 0 and 25, and an even wider gap between -10 and 25. During that time, jump (or Jump) is still true. But worse than that, it looks like you're capping vspeed at 20, so it will never be greater than 25. That is, if what you marked as your Create event is also in the Step event. If not, then you're just not doing a lot of things that you need to be doing.

Finally,
if (!Jump) { if keyboard_check(vk_space) { vspeed = 0; } }
This is going to break so many things if you fix all of the other problems. You'll find that the character immediately falls to the ground when you try to jump. There's no reason to do this. If you meant "if !keyboard_check" then you have to put that, but even so, that's going to leave your character floating in the air whenever the player isn't pressing the spacebar.
 

Joe Ellis

Member
@BrolyDev It should work if you check "if gravity == 0" before jumping:

GML:
if keyboard_check_pressed(vk_space)
&& gravity == 0
{vspeed = -10}
You could put the keyboard check inside the else of the place_free check, but it'd probably make it more cluttered later on.
Checking if gravity == 0 is better than vspeed, cus it's possible for vspeed to == 0 when it's at the top of the jump arc, so then it could keep jumping in mid air.
The place_free check should be in the step event aswell cus the create event is only run once when the instance is created.
 
Last edited:
@BrolyDev It should work if you check "if gravity == 0" before jumping:

GML:
if keyboard_check_pressed(vk_space)
&& gravity == 0
{vspeed = -10}
You could put the keyboard check inside the else of the place_free check, but it'd probably make it more cluttered later on.
Check if gravity == 0 is better than vspeed, cus it's possible for vspeed to == 0 when it's at the top of the jump arc, so then it could keep jumping in mid air.
The place_free check should be in the step event aswell cus the create event is only run once when the instance is created.
Why bother checking his gravity, he sets it in the create event, it will never ever change. The OP had the balls to even say "Gravity is not my real problem, the truth works quite well for me, what I ask for help is that I only jump when I touch the ground", so yeah...
 

Joe Ellis

Member
Why bother checking his gravity, he sets it in the create event, it will never ever change. The OP had the balls to even say "Gravity is not my real problem, the truth works quite well for me, what I ask for help is that I only jump when I touch the ground", so yeah...
Well it looked like the code in the create event should be in the step event, and controlling the gravity depending whether it's on the ground or not..
 
Well it looked like the code in the create event should be in the step event, and controlling the gravity depending whether it's on the ground or not..
Absolutely. The "regular" way to do this is really just "activating" the gravity effect on the player when he's not on the ground. Implying this has to be checked more often than just at object creation
 

BrolyDev

Member
[QUOTE = "Slow Fingers, publicación: 524276, miembro: 57580"]
¿Por qué molestarse en comprobar su gravedad? Lo pone en el evento de creación, nunca cambiará. El OP tuvo las pelotas de decir "La gravedad no es mi problema real, la verdad me funciona bastante bien, lo que pido ayuda es que solo salto cuando toco el suelo", así que sí ...
[/CITA]thanks
 
Top