Vertical Gunkick and Jumping

Hi, I made a short video to explain my problem a bit better:


As you can see in the video the player jumps a bit when shooting down after being in the air for a bit and then shooting downwards the player doesn't really move much. However when the player jumps and then shoots downwards directly after he jumps he reaches a much higher point.

It is a bit hard for new players to get the timing right on that however since shooting just before jumping also has little to no effect.

I want the kick to always be the same or have a simmilar effect even without jumping at the exact right moment.

I have a gunkicky variable (displayed directly above the player), the min&max depends on the weapon, the shotgun has a range of 5 and -5 and the pistols are 2 and -2. I'm pretty sure the problem isn't here.

Then theres a grv and a vsp.

My code for mooving vertically looks like this:

create
GML:
vsp = 0;
grv = 0.3;
step
GML:
vsp  += grv + gunkicky;   
gunkicky = 0;

//Vertical Collision
if (place_meeting(x,y+vsp,oWall))
{
    while(!place_meeting(x,y+sign(vsp),oWall))
    {
        y= y + sign(vsp);
    }
    vsp = 0;
}

//Mooving vertically
y += vsp;
Jumping is basically just vsp += -jumpspeed;
But its fine since the player is on the ground and vsp is 0.
I can't do vsp = gunkicky; since that would allow the player to fly.

It would be awesome if you could help me!
 

Ommn

Member
try this in Step Event:
GML:
if gunkicky<0{vsp=gunkicky;}else{vsp+=grv+gunkicky;}
gunkicky = 0;
 
Hi, sorry for the late reply.
Your code seems to work as intended only when the player is either standing on the ground or at the climax of a jump
but when the player is mid jump the vsp gets reset when shooting and the player abruptly stops and falls down again:
 

Ommn

Member
try:
GML:
if gunkicky!=0{vsp=gunkicky>0? -gunkicky: gunkicky;}else{vsp+=grv+gunkicky;}
gunkicky = 0;
 

TheouAegis

Member
Why are you increasing VSP? Why aren't you just adding gunkicky to the y coordinate directly? You would need separate collision checks, but whatever - it's just one instance. The point is you are directly modifying vsp, so if you are adding-2 when you set the vsp to -7, you are going to get that giant kick at the very beginning because vsp becomes -9; however if you add -2 when vsp is +2, vsp becomes 0, so unless you have no firing delay, the vsp will never be negative enough to climb up via gunfire.
 
That is a good point and I have gotten it to work with a second collision check now, but there now is the problem of the player teleporting the amount of gunkicky.
How would you go about making the player move smoothly and not teleporting?
My code now looks like this:
GML:
if (place_meeting(x,y+gunkicky,oWall))
{
    while(!place_meeting(x,y+sign(gunkicky),oWall))
    {
        y= y + sign(gunkicky);
    }
    gunkicky = 0;
}


y += vsp;//Mooving vertically
y += gunkicky;//Applying kick
gunkicky *= 0.98;
if(gunkicky<0.1) gunkicky=0;
Of course gunkicky is no longer added to vsp and I did have to increase the amount of gunkicky for each weapon since the shotgun for example would only kick the player 5 pixel upwards, its now 50.
 

Ommn

Member
Your solution seems logical, but I see that the multiplication factor 0.98 is very large.
try 0.6 or less

good luck;)
 

TheouAegis

Member
In terms of actual physics, your original code is reasonably correct. Shooting a gun downwards with that much kick wood modify the vertical vector, so shooting a gun right when you start jumping, especially since the ground is so close to the tip of the gun at that point, would be more pronounced on the way up and less pronounced on the way down. If you want the gun to kick up even on the way down, then you are going to have to defy physics. If you want the gun to not actually modify the vertical vector and thus be consistent across the period of the jump, then again you're going to need to defy physics. My suggestion and those cases would be too perhaps try treating gunkicky as it's own vertical Vector accelerated by gravity. So add vsp AND also add gunkicky to y.
 

TheouAegis

Member
It's going to be abrupt because you're firing a gun. Did you try doing something like
Code:
gunkicky += grv;
if gunkicky > 0
    gunkicky = 0;
vsp += grv;
y += vsp + gunkicky;
You could perhaps keep adding gunkicky to vsp every step, but I don't know how that would look.
Code:
gunkicky *= 4/5;
vsp += grv + gunkicky;
But I still foresee a greater kick at the start of the jump than near the peak of the jump.
 
Top