• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

[SOLVED] Problem with skid

M

molcap

Guest
Hi everybody!

I'm trying to do a skid system for my game, but it works fine until you press left and right at the same time and I don't know why, when I do that the sprite changes to idle with 0 of image speed and if I press left and change to right too fast he doesn't skid. Also I want to implement a system to run using double tap.

Here's the code:

Code:
if (Key_Left)
        {
            if sign(hsp) <= 0 and not !(Key_Right)
            {
                hsp = -2.2*run_speed;
                if (grounded)
                {
                    flip = -1;
                    sprite_index = run
                }
            }
            else
            {
                if hsp > traction
                {
                    hsp -= traction;
                    sprite_index = skid
                }
                else
                hsp = 0
            }
        }
        
        
        if (Key_Right)
        {
            if sign(hsp) >= 0 and !(Key_Left)
            {
                hsp = 2.2*run_speed;
                if (grounded)
                {
                    flip = 1;
                    sprite_index = run
                }
            }
            else
            {
                if hsp < traction
                {
                    hsp += traction;
                    sprite_index = skid
                }
                else
                hsp = 0
            }
        }
        
        //Neutral input = 0 movement
        if ((Key_Right && Key_Left) or (!Key_Right && !Key_Left))
        {
            if hsp > traction and sign(hsp) = 1
            {
                hsp -= traction;
                sprite_index = skid
            }
            else if hsp < traction and sign(hsp) = -1
            {
                hsp += traction;
                sprite_index = skid
            }
            else
            {
                hsp = 0
            }
            if fallspecial = false and hsp = 0
            {
                sprite_index = idle
            }
        }
Thanks
 
S

stephen2017

Guest
So every step in the game the neutral condition is being filled? By this I mean your if condition comes true when your not pressing both the right and left at all
or (!Key_Right && !Key_Left) so its active all the time? Or is the mechanics different?

On another one I think I read somewhere else on the forums that multiple key statements need to be checked first before single ones because you are already fulling the above if condition and it will do that one before even checking the one below. as the code goes through line by line and does what it finds first.
 
M

molcap

Guest
So every step in the game the neutral condition is being filled? By this I mean your if condition comes true when your not pressing both the right and left at all
or (!Key_Right && !Key_Left) so its active all the time? Or is the mechanics different?
Condition comes true when you're pressing left and right or when neither is pressed

On another one I think I read somewhere else on the forums that multiple key statements need to be checked first before single ones because you are already fulling the above if condition and it will do that one before even checking the one below. as the code goes through line by line and does what it finds first.
What do you mean? should I check neutral imput before checking movement?

It worked! Thank you
 
S

stephen2017

Guest
Sweet just needed to check the wording on your neutral condition. But yes Neutral condition first as it is a multiple key event and these should be checked first. If you do the right key before this, that condition will come true so it will not check the others as it starts at the top and finds the first condition that comes trues then applies that. As far as I know this it the way the coding works.
 
Top