GML Jump and fire with collision issue

neutro

Member
Hello guys.
I got this problem with the collision while next to a wall, pressing against the wall and firing.
Is it the horizontal or vertical collision or both that is not correctly coded?
Anyone here who has ideas how to solve this?


code in fire state script:

GML:
vsp = vsp + grv;

if (image_xscale = 1) && (hsp != 0) {
    hsp = 0.6 * walksp;
}
else if (hsp == 0) && (image_xscale = 1) {
    hsp = 0 * walksp;
}
else if (hsp == 0) && (image_xscale = -1) {
    hsp = 0 * -walksp;
}
else {
    hsp = 0.6 * -walksp;
}

// Horizontal collision
if (place_meeting(x+hsp,y,oWall)) {
    while (!place_meeting(x+sign(hsp),y,oWall))
    {
        x = x + sign(hsp);
    }
    hsp = 0;
    
}
x = x + hsp;

// Vertical collision
if (place_meeting(x,y+vsp,oWall)) {
    while (!place_meeting(x,y+sign(vsp),oWall))
    {
        y = y + sign(vsp);
    }
    vsp = 0;
}
if (jump_up) && (state == "fire") && (place_meeting(x+hsp,y,oWall)) {
    vsp = -jumpsp;
}
y = y + vsp;

image_speed = 1;
sprite_index = sPlayerFire;
 

neutro

Member
I suspect your bounding boxes are not the same for the different sprites, and you're checking for collisions before changing the sprite.
Ok, so I've managed to have the player fall down correctly AFTER the snowball throw, this by decreasing the width of the collision box on the jump/fall sprite.
Still, the gravity don't apply while the fire animation runs while the player is in air and against the wall. Thoughts on this?
 

Mk.2

Member
The code you've posted doesn't give a complete picture of everything that is happening, but it does show that you're setting vsp to -jumpspd if colliding with a wall and "jump_up" = true.

You mentioned changing the collision box on the jump/fall sprite, but is it the same width as the fire animation sprite? And the same origin? It's generally a good idea to have the same mask for sprite changes, with some exceptions (like crouching/sliding etc) to prevent it overlapping walls.
 
Last edited:

neutro

Member
The code you've posted doesn't give a complete picture of everything that is happening, but it does show that you're setting vsp to -jumpspd if colliding with a wall and "jump_up" = true.

You mentioned changing the collision box on the jump/fall sprite, but is it the same width as the fire animation sprite? And the same origin? It's generally a good idea to have the same mask for sprite changes, with some exceptions (like crouching/sliding etc) to prevent it overlapping walls.
So, this is code is the problem?
In fire state script:
GML:
// Vertical collision
if (place_meeting(x,y+vsp,oWall))
{
    while (!place_meeting(x,y+sign(vsp),oWall))
    {
        y = y + sign(vsp);
    }
    vsp = 0;
}
if (jump_up) && (state == "fire") && (place_meeting(x+hsp,y,oWall))
{
    vsp = -jumpsp;
}
y = y + vsp;
jumpsp is set to 2.4 in the oPlayer create event.
this is the jump code in move/collide state script:
GML:
// jump
if (place_meeting(x,y+1,oWall)) && (jump_up)
{
    vsp = -jumpsp;
    audio_play_sound(sfx_jump, 5, false);
}
while jumping freely -with or without firing- and jumping while against a wall -and NOT firing- the gravity works correct.
 

neutro

Member
What is the purpose of this?
It’s noob-non logic-mumbo-jumbo-code and I don’t remember exactly why I wrote those lines but probably because of trying to solve the issue with no gravity when against a oWall and firing.
 

Nidoking

Member
It’s noob-non logic-mumbo-jumbo-code and I don’t remember exactly why I wrote those lines but probably because of trying to solve the issue with no gravity when against a oWall and firing.
I'll go out on a limb and say that if you don't know what it's supposed to do, the chances that Game Maker is going to turn it into an output that you want are effectively zero. Do with that knowledge what you will.
 

Sabnock

Member
I would try moving the Jump check to after the y = y + vsp; as well as you are ignoring the vertical collision detection the way you currently have it or move it to before the Vertical collision detection. Either way would work i guess.

GML:
y = y + vsp;

if (jump_up) && (state == "fire") && (place_meeting(x+hsp,y,oWall)) {
    vsp = -jumpsp;
}
Also shouldn't this code just be


GML:
if (jump_up) {

    vsp = -jumpsp;

}
 
Last edited:

Mk.2

Member
i would try moving the Jump check to after the y = y + vsp; as well as you are ignoring the vertical collision detection the way you currently have it. Or move it to before the Vertical collision detection. either way would work i guess.

GML:
y = y + vsp;

if (jump_up) && (state == "fire") && (place_meeting(x+hsp,y,oWall)) {
    vsp = -jumpsp;
}
Look at what this code is doing though. It's checking that state == "fire", redundant since this is inside the fire state script. Then checking that the player is next to a wall, in order to set the vsp to -jumpspd. That's the opposite behaviour of what neutro is trying to achieve, plus they already mentioned that they know it doesn't make sense. Removing that part of the code seems like a good start to resolving the issue.

EDIT: Looks like you editted right before I posted this.
 
Top