GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2017-02-12 14:37:24

phinto
Member
Registered: 2015-05-30
Posts: 7

BOX pushing probs

okay, my issue is that I have the push code but this turns out wrong, just look at vid.

ja, this box sticks to player when I climb ladder, and pass through me.
and it didn't trigger the push animation as I tried to.

helped by benji

its for collition.

///check Collision(x, y)

var xpos = argument[0];
var ypos = argument[1];

if (place_meeting(xpos, ypos, obj_platform)) // Check for collisions against normal blocks
  {
  return true;
  }
else

  
  {
  // Check for collisions against jump-through platforms
  var platform = instance_place(xpos, ypos, obj_jumpthrough_platform);
  if (platform == noone)
    return false;
  if (image_blend == c_red) // If it's in red mode, allow moving up through it, but not falling down
    return ((vsp > 0 and bbox_bottom <= platform.bbox_top) or (vsp == 0 and bbox_bottom < platform.bbox_bottom));
  else
    return (vsp <= 0 and bbox_bottom > platform.bbox_bottom); // When in cyan mode, allow falling through, but not jumping up or walking through it
   }
 // return false;
  
 return false;
    
    

//by benjamin ...............................................................................


// { // Check for collisions against jump-through platforms
//  var platform = instance_place(xpos, ypos, obj_jumpthrough_platform_2);
//  if (platform == noone)
//    return false;
//  if (image_blend == c_aqua) // If it's in red mode, allow moving up through it, but not falling down
//    return ((vsp < 0 and bbox_bottom >= platform.bbox_top) or (vsp == 0 and bbox_bottom > platform.bbox_bottom));
//  else
//    return (vsp >= 0 and bbox_bottom < platform.bbox_bottom); // When in cyan mode, allow falling through, but not jumping up or walking through it
//    }

and this is for the player

///player script

// player output.................................................

if !stop
KyR = keyboard_check_direct(vk_right);
KyL = -keyboard_check_direct(vk_left); 
KyJ = keyboard_check_pressed(vk_up);
KyU = keyboard_check_direct(vk_up);
KyD = keyboard_check_direct(vk_down);
// react inputs..................................................

if !stop
move = KyL + KyR;


if !stop 
hsp = move * msp;


if !stop
if (vsp < 10) vsp += grav;


if !stop
if (checkCollision(x,y+1))
 {
   vsp = KyJ * -jsp
 }


//push animation................................................

if !stop
if (checkCollision(x+hsp,y,obj_box))
 {
   sprite_index = any_push;
}

// push............................................................ooo__________________________________________-
if !stop + !ladder
with (instance_place(x+image_xscale, y, obj_box))
{
  // x += other.hsp;   or  image_xscale = move;
   x +=other.hsp;
}

// horizontal...................................................

if !stop
if (checkCollision(x+hsp,y))
{
 while(!checkCollision(x+sign(hsp),y))
  {
    x += sign(hsp);
  }
  hsp = 0;
}
x += hsp;

// vertical...................................................

if !stop
if (checkCollision(x,y+vsp))
{
while(!checkCollision(x,y+sign(vsp)))
  {
    y += sign(vsp);
  }
  vsp = 0;
}
y += vsp;

//.....................................................................


// animate......................................................     
  
if !(ladder)
{
if !stop
if (move!=0) image_xscale = move;
image_speed = 0.5;
    if (checkCollision(x,y+1))
     {
        if (move!=0) sprite_index = any_run; else sprite_index = any_stand;
     }
    else
     {
        if (vsp < 0) sprite_index = any_jump; else sprite_index = any_fall;
     }
}

//push animation...................................................................................

// bounce spring................................................

var inst = instance_place(x, y, obj_spring);
if (inst != noone)
{
if (inst.y > y+16)
  {
 vsp = -jps;
  }
} 


//exit...........................................................
if stop = true
{
sprite_index = any_stand
vsp = 0
hsp = 0
}

//death..........................................................
if !deathless 
if (place_meeting(x,y,obj_death_par))
{
deathless = true;
alarm[0] = 80;
lives-=3;
audio_play_sound(sou_hurt,1,0);
}


//deathless........................................................
if deathless = true
{
  image_alpha = 0.5;
}
else
{
  image_alpha = 1;
}

//hit by or bounce on enemy.................................................................
if !deathless
if instance_place(x,y,obj_enemy_par)
{
    if (obj_enemy_par.y > y+16)
    {
        obj_enemy_par.HP-=1;
        vsp = -jsp;
        audio_play_sound(sou_enemyhit,1,0);
    }
    else
    {
      hsp = -image_xscale*1;
      vsp = -3;
      deathless = true
      alarm[0] = 80;
      lives-=1;
      audio_play_sound(sou_hurt,1,0);
    }
}

//hit by invincenemy.................................................................
if !deathless
if instance_place(x,y,obj_bullet_par)
{
      hsp = -image_xscale*1;
      vsp = -3;
      deathless = true
      alarm[0] = 80;
      lives-=1;
      audio_play_sound(sou_hurt,1,0);
}

// convayor.......................................................
if !stop
if (place_meeting(x,y+1,obj_convayor_platform))
{
if (other.image_blend == c_red)
{x-=1.5} 
else
{x+=1.5}
}



//Ladder.....................................................................................
if (KyU || KyD)
{
    if place_meeting(x,y,par_ladder) ladder = true;
}

if (ladder)
{
    vsp = 0;
    grav = 0;
    if (KyU) vsp = -2 ;
    if (KyD) vsp = 2 ;
    
    if !place_meeting(x,y,par_ladder)
    ladder = false;  
   
}
if !(ladder)
grav = 0.3;

//ladder animation............................................................
if (ladder)
{
    sprite_index = any_climb;
    image_speed = 0;
    if (KyU) image_speed = 0.2;
    if (KyD) image_speed = 0.2;
}
//stuck death............................................................


if place_meeting(x,y, obj_platform_red) 
 {
  deathless = true;
  alarm[0] = 80;
  lives-=3;
  audio_play_sound(sou_hurt,1,0);
 }

if place_meeting(x,y, obj_platform_cyan) 
 {
  deathless = true;
  alarm[0] = 80;
  lives-=3;
  audio_play_sound(sou_hurt,1,0);
 }


//.........................................................................................

have I miss something?

Offline

#2 2017-02-17 20:04:43

xot
Administrator
Registered: 2007-08-18
Posts: 1,201

Re: BOX pushing probs

Hardly anyone reads these forums. You're much more likely to get help on the GMC. I don't see this information posted there, though.

https://forum.yoyogames.com/index.php?t … ics.19815/


Abusing forum power since 1986.

Offline

Board footer

Powered by FluxBB