L
lohtangclan
Guest
Hi all...
I'm trying to make a lemmings-y object that walks left and right & falls down whenever there's a gap in my ds_grid. eg. a 0..
At the moment I spawn the object in by clicking a button. It falls correctly (ie at the speed I want) when I spawn it, but after it has hit some ground and then walks off a second edge, it immediately teleports (for lack of a better word) to the closest y=1 ground, instead of falling according to my set speed. I've enclosed the step event of my lemming object..
I've also noticed it doesn't *seem* to enter the if(on_ground==0) , as it never changes sprite to s_falling on the second fall. I've tested out putting show_message("falling"); into the if statement and it also only ever displays when the object is spawned & falling... But yet..it falls?!
So.... where am I going wrong..and how do I make sure the object enters falling state correctly?
Thanks..
I'm trying to make a lemmings-y object that walks left and right & falls down whenever there's a gap in my ds_grid. eg. a 0..
At the moment I spawn the object in by clicking a button. It falls correctly (ie at the speed I want) when I spawn it, but after it has hit some ground and then walks off a second edge, it immediately teleports (for lack of a better word) to the closest y=1 ground, instead of falling according to my set speed. I've enclosed the step event of my lemming object..
I've also noticed it doesn't *seem* to enter the if(on_ground==0) , as it never changes sprite to s_falling on the second fall. I've tested out putting show_message("falling"); into the if statement and it also only ever displays when the object is spawned & falling... But yet..it falls?!
So.... where am I going wrong..and how do I make sure the object enters falling state correctly?
Thanks..
Code:
var calc_v_move=o_control.time_passed*grav; //delta time x gravity
on_ground=is_on_ground(x,y); //simple external script that checks grid value of y+1 for 0 or 1
if(on_ground==0){
sprite_index=s_falling;
var i=1;
//the calc_v_move is how much the lemming should fall in 1 frame, so whilst it is free to fall, move it
while(i<=calc_v_move&&on_ground==0){
i++;
y++;
on_ground=is_on_ground(x,y);
}
}
var side_hit=0;//side collision flag
var endLoop=false;
if(on_ground==1){//on ground obvs
sprite_index=s_dog;
if(x>room_width-5){
travel_dir=-1;
}
if(x<5){
travel_dir=1;
}
if(travel_dir==1){
var i=bbox_top;
while(endLoop==false){
if(global.screenGrid[# x+1,i]==1){//check to the side of object for collision
side_hit=1;
if(y-i<slope_height){
y=i-1;
side_hit=0;//reset detector
endLoop=true;
}
else{//not less than slope means too steep, turn around
travel_dir=-1;
side_hit=1;
endLoop=true;
}
}
else i++;
}
//side is clear
if(side_hit!=1){
x+=1;
}
}
if(travel_dir==-1){
var i=bbox_top;
while(endLoop=false){
if(global.screenGrid[# x-1,i]==1){//check to the side of object for collision
if(y-i<slope_height){
y=i-1;
side_hit=0;//reset detector
endLoop=1;
}
else{
travel_dir=1;
side_hit=1;
endLoop=1;
break;//too steep
}
}
else i++;
}
//side is clear
if(side_hit!=1){
x+=-1;
}
}
}