Skip when moving

N

Normalize

Guest
Hi im following this tutorial on youtube, but when my character drops to the ground. it skips along the floor. and some times it get stuck in the wall. and when i hit a wall i skip again. anyone have a solution?
 

YoKoNo

Member
Without looking at the code, all I can say is that I've had something similar to this.

mine was my code was in the wrong section of the {} brackets, have a look to see if you have put your code in the right sections.

{
{
#some code
#missing code should be here X
}
code shouldn't be here should be in spot X
}

If its not in the right place you will get weird glitches.

Hope this explains it clearly.

P
 
N

Normalize

Guest
Without looking at the code, all I can say is that I've had something similar to this.

mine was my code was in the wrong section of the {} brackets, have a look to see if you have put your code in the right sections.

{
{
#some code
#missing code should be here X
}
code shouldn't be here should be in spot X
}

If its not in the right place you will get weird glitches.

Hope this explains it clearly.

P
btw the code is the same as the dude from youtube, but it dosn't work the same as him.
Here is my code:


key_left = keyboard_check(vk_left);

//This check if a user is holding down right key on keyboard
key_right = keyboard_check(vk_right);

//This check if the user is pressing down space bar
key_jump = keyboard_check_pressed(vk_space);

//Var er midlertidig skjer bare 1 frame? 0 - 1 = move = -1 eller +1
//Dette er får at du ikke kan presse left elr right samtidig
var move = key_right - key_left;

//Dette er -1 elr +1 gange walksp som er 4. Farten vi vil gå i spillet
hsp = move * walksp;

//gravitasjon
vsp = vsp + grv;

if (place_meeting(x,y+1,oWall)) and (key_jump)
{
vsp = -7;
}



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

}
//X er horizontal direksjon. Dette er -4 eller +4. hsp = 4 pixla
x = x + hsp;


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

}
//X er horizontal direksjon. Dette er -4 eller +4. hsp = 4 pixla
y = y + vsp;
 

StormGamez

Member
I'm guessing your trying to make a platformer, if thats the case theres another way to do this so its a bit easier to read

Code:
//Player input
right = keyboard_check(vk_right)
left = keyboard_check(vk_left)
jump = keyboard_check_pressed(vk_space)

//Set move to -1, 0 or 1
move = -left + right
//Note: When you press a button it give a value of 1 and when is not pressed its a 0, aka binary on or off

//Set gravity
if(!place_meeting(x,y+1,[insert object here]) {
     if(vspd < 10) { //Setting a terminal velocity for player
         vspd += 1
     }  else vspd = 10
} else vspd = 0

//Movement code horizontally
if(!place_meeting(x+move,y,[insert object here])) { //Checking to see if not touching objectdirectly to the right
    if(!place_meeting(x+hspd,y,[insert object here])) { //Checking to see if object is 2 steps ahead of us
        hspd = 2*move
        //move if nothing in the way
    } else hspd = move //Slow down if object near in direction of travel
} else hspd = 0 //Stop if object is infront of us

//Move player by hspd
x+=hspd

//Vertical movement
if(place_meeting(x,y+1,[insert object here])){ //Jump if touching a floor
    vspd = -7
}

//Vertical collisions
if(!place_meeting(x,y+1,[insert object here])) { //If not about to hit a object above or bellow do next code
    if(!place_meeting(x,y+vspd,[insert object here])) { //Move if not going to hit anything
        y+=vspd
    } else y+=sign(vspd) // Slow down if about to hit object
} else vspd = 0 //Stop moving vertically
Hopefully that code works and its based on Shaun Spalding movement code if you want to use his version instead
-Best regards SG
 
N

Normalize

Guest
I'm guessing your trying to make a platformer, if thats the case theres another way to do this so its a bit easier to read

Code:
//Player input
right = keyboard_check(vk_right)
left = keyboard_check(vk_left)
jump = keyboard_check_pressed(vk_space)

//Set move to -1, 0 or 1
move = -left + right
//Note: When you press a button it give a value of 1 and when is not pressed its a 0, aka binary on or off

//Set gravity
if(!place_meeting(x,y+1,[insert object here]) {
     if(vspd < 10) { //Setting a terminal velocity for player
         vspd += 1
     }  else vspd = 10
} else vspd = 0

//Movement code horizontally
if(!place_meeting(x+move,y,[insert object here])) { //Checking to see if not touching objectdirectly to the right
    if(!place_meeting(x+hspd,y,[insert object here])) { //Checking to see if object is 2 steps ahead of us
        hspd = 2*move
        //move if nothing in the way
    } else hspd = move //Slow down if object near in direction of travel
} else hspd = 0 //Stop if object is infront of us

//Move player by hspd
x+=hspd

//Vertical movement
if(place_meeting(x,y+1,[insert object here])){ //Jump if touching a floor
    vspd = -7
}

//Vertical collisions
if(!place_meeting(x,y+1,[insert object here])) { //If not about to hit a object above or bellow do next code
    if(!place_meeting(x,y+vspd,[insert object here])) { //Move if not going to hit anything
        y+=vspd
    } else y+=sign(vspd) // Slow down if about to hit object
} else vspd = 0 //Stop moving vertically
Hopefully that code works and its based on Shaun Spalding movement code if you want to use his version instead
-Best regards SG
Thank you i am gonna try that out.
 

StormGamez

Member
Thank you i am gonna try that out.
Please DO NOT use that code, just tested it and it didn't work, please use the following FIXED and TESTED code
Code:
//Player input
right = keyboard_check(vk_right)
left = keyboard_check(vk_left)
jump = keyboard_check_pressed(vk_space)

//Set move to -1, 0 or 1
move = -left + right
//Note: When you press a button it give a value of 1 and when is not pressed its a 0, aka binary on or off

//Set gravity
if(!place_meeting(x,y+1,obj_wall)) {
     if(vspd < 10) { //Setting a terminal velocity for player
         vspd += 1
     }  else vspd = 10
} else vspd = 0

//Movement code horizontally
if(!place_meeting(x+move,y,obj_wall)) { //Checking to see if not touching objectdirectly to the right
    if(!place_meeting(x+hspd,y,obj_wall)) { //Checking to see if object is 2 steps ahead of us
        hspd = 4*move
        //move if nothing in the way
    } else hspd = move //Slow down if object near in direction of travel
} else hspd = 0 //Stop if object is infront of us

//Move player by hspd
x+=hspd

//Vertical movement
if(place_meeting(x,y+1,obj_wall) and jump){ //Jump if touching a floor
    vspd = -16
}

//Vertical collisions
if(!place_meeting(x,y+sign(vspd),obj_wall)) { //If not about to hit a object above or bellow do next code
    if(!place_meeting(x,y+vspd,obj_wall)) { //Move if not going to hit anything
        y+=vspd
    } else y+=sign(vspd) // Slow down if about to hit object
} else vspd = 0 //Stop moving vertically
you may also need to initialize the variables "vspd" and "hspd" in your create event

-Best Regards SG
 
N

Normalize

Guest
Please DO NOT use that code, just tested it and it didn't work, please use the following FIXED and TESTED code
Code:
//Player input
right = keyboard_check(vk_right)
left = keyboard_check(vk_left)
jump = keyboard_check_pressed(vk_space)

//Set move to -1, 0 or 1
move = -left + right
//Note: When you press a button it give a value of 1 and when is not pressed its a 0, aka binary on or off

//Set gravity
if(!place_meeting(x,y+1,obj_wall)) {
     if(vspd < 10) { //Setting a terminal velocity for player
         vspd += 1
     }  else vspd = 10
} else vspd = 0

//Movement code horizontally
if(!place_meeting(x+move,y,obj_wall)) { //Checking to see if not touching objectdirectly to the right
    if(!place_meeting(x+hspd,y,obj_wall)) { //Checking to see if object is 2 steps ahead of us
        hspd = 4*move
        //move if nothing in the way
    } else hspd = move //Slow down if object near in direction of travel
} else hspd = 0 //Stop if object is infront of us

//Move player by hspd
x+=hspd

//Vertical movement
if(place_meeting(x,y+1,obj_wall) and jump){ //Jump if touching a floor
    vspd = -16
}

//Vertical collisions
if(!place_meeting(x,y+sign(vspd),obj_wall)) { //If not about to hit a object above or bellow do next code
    if(!place_meeting(x,y+vspd,obj_wall)) { //Move if not going to hit anything
        y+=vspd
    } else y+=sign(vspd) // Slow down if about to hit object
} else vspd = 0 //Stop moving vertically
you may also need to initialize the variables "vspd" and "hspd" in your create event

-Best Regards SG
okei i am gonna try this code now :) thank you.
 
N

Normalize

Guest
Please DO NOT use that code, just tested it and it didn't work, please use the following FIXED and TESTED code
Code:
//Player input
right = keyboard_check(vk_right)
left = keyboard_check(vk_left)
jump = keyboard_check_pressed(vk_space)

//Set move to -1, 0 or 1
move = -left + right
//Note: When you press a button it give a value of 1 and when is not pressed its a 0, aka binary on or off

//Set gravity
if(!place_meeting(x,y+1,obj_wall)) {
     if(vspd < 10) { //Setting a terminal velocity for player
         vspd += 1
     }  else vspd = 10
} else vspd = 0

//Movement code horizontally
if(!place_meeting(x+move,y,obj_wall)) { //Checking to see if not touching objectdirectly to the right
    if(!place_meeting(x+hspd,y,obj_wall)) { //Checking to see if object is 2 steps ahead of us
        hspd = 4*move
        //move if nothing in the way
    } else hspd = move //Slow down if object near in direction of travel
} else hspd = 0 //Stop if object is infront of us

//Move player by hspd
x+=hspd

//Vertical movement
if(place_meeting(x,y+1,obj_wall) and jump){ //Jump if touching a floor
    vspd = -16
}

//Vertical collisions
if(!place_meeting(x,y+sign(vspd),obj_wall)) { //If not about to hit a object above or bellow do next code
    if(!place_meeting(x,y+vspd,obj_wall)) { //Move if not going to hit anything
        y+=vspd
    } else y+=sign(vspd) // Slow down if about to hit object
} else vspd = 0 //Stop moving vertically
you may also need to initialize the variables "vspd" and "hspd" in your create event

-Best Regards SG
I GOT IT!! THANKs
Well it kinda worked out, but now i dont have any gravity..
 
Last edited by a moderator:

StormGamez

Member
I GOT IT!! THANKs
Well it kinda worked out, but now i dont have any gravity..
that's strange.. it should work... ill look into it and see if anything out of the ordinary happens on my side

-Edit
if you jump and you dont fall then something might be wrong with this code..
Code:
//Set gravity
if(!place_meeting(x,y+1,obj_wall)) {
     if(vspd < 10) { //Setting a terminal velocity for player
         vspd += 1
     }  else vspd = 10
} else vspd = 0
otherwise if you cant jump or fall it might be something to do with this code
Code:
//Vertical collisions
if(!place_meeting(x,y+sign(vspd),obj_wall)) { //If not about to hit a object above or bellow do next code
    if(!place_meeting(x,y+vspd,obj_wall)) { //Move if not going to hit anything
        y+=vspd
    } else y+=sign(vspd) // Slow down if about to hit object
} else vspd = 0 //Stop moving vertically
nothing strange happened on my version of game maker (running 1.4) so it must be because of your version or something else...
Best regards - SG
 
N

Normalize

Guest
that's strange.. it should work... ill look into it and see if anything out of the ordinary happens on my side

-Edit
if you jump and you dont fall then something might be wrong with this code..
Code:
//Set gravity
if(!place_meeting(x,y+1,obj_wall)) {
     if(vspd < 10) { //Setting a terminal velocity for player
         vspd += 1
     }  else vspd = 10
} else vspd = 0
otherwise if you cant jump or fall it might be something to do with this code
Code:
//Vertical collisions
if(!place_meeting(x,y+sign(vspd),obj_wall)) { //If not about to hit a object above or bellow do next code
    if(!place_meeting(x,y+vspd,obj_wall)) { //Move if not going to hit anything
        y+=vspd
    } else y+=sign(vspd) // Slow down if about to hit object
} else vspd = 0 //Stop moving vertically
nothing strange happened on my version of game maker (running 1.4) so it must be because of your version or something else...
Best regards - SG
no it all workedout great :) thankyou for your time sir :)
 
Top