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?
btw the code is the same as the dude from youtube, but it dosn't work the same as him.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
//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
Thank you i am gonna try that out.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
Hopefully that code works and its based on Shaun Spalding movement code if you want to use his version insteadCode://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
-Best regards SG
Please DO NOT use that code, just tested it and it didn't work, please use the following FIXED and TESTED codeThank you i am gonna try that out.
//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
okei i am gonna try this code now thank you.Please DO NOT use that code, just tested it and it didn't work, please use the following FIXED and TESTED code
you may also need to initialize the variables "vspd" and "hspd" in your create eventCode://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
-Best Regards SG
I GOT IT!! THANKsPlease DO NOT use that code, just tested it and it didn't work, please use the following FIXED and TESTED code
you may also need to initialize the variables "vspd" and "hspd" in your create eventCode://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
-Best Regards SG
that's strange.. it should work... ill look into it and see if anything out of the ordinary happens on my sideI GOT IT!! THANKs
Well it kinda worked out, but now i dont have any gravity..
//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
//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
no it all workedout great thankyou for your time sirthat'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..
otherwise if you cant jump or fall it might be something to do with this codeCode://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
nothing strange happened on my version of game maker (running 1.4) so it must be because of your version or something else...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
Best regards - SG