Jump to content


Photo

How to check for collisions


  • Please log in to reply
9 replies to this topic

#1 white_boi

white_boi

    GMC Member

  • New Member
  • 44 posts
  • Version:GM8

Posted 09 February 2012 - 09:58 PM

ok im back for millionth time this week,
alright to start it isn't as easy as the title says. I have a character that i recently made roll, but now another problem occurs when he rolls he completely ignores any solids! I have the object itself set to stop at all Solids, and all the roll does is speed him up for a split second and change his sprite to one of him rolling! can someone help?

heres the code i'm using for the roll:
C-Key:
global.roll = true;

Step Event:
if global.roll=true{
  if keyboard_check (vk_up)
        {sprite_index= sprLinkJumpU; speed = 4; direction = 90; break;}
else
    if keyboard_check (vk_down)
        {sprite_index= sprLinkJumpD;speed = 4; direction = 270; break;}
else
    if keyboard_check (vk_left)
        {sprite_index= sprLinkJumpL;speed = 4; direction = 180; break;}
else
    if keyboard_check (vk_right)
        {sprite_index= sprLinkJumpR; speed = 4; direction = 360; break;
    }
    sound_play (choose(sndLink_Roll_1,sndLink_Roll_2,sndLink_Roll_3));
}

Animation End Event:
//Stop Rolling 
if global.is_rolling= true or sprite_index =5{
    if global.facing= "U"
        {speed=0;sprite_index = sprLinkStandU;}  
else
    if global.facing= "D"
        {speed=0;sprite_index = sprLinkStandD;}
else    
    if global.facing= "L"
        {speed=0;sprite_index = sprLinkStandD;}
else    
    if global.facing= "R"
        {speed=0;sprite_index = sprLinkStandD;}
    global.roll=false;
    }   

is there anything interfering with the collisions of this object?
  • 0

#2 thegame

thegame

    Flying Penguin

  • GMC Member
  • 1495 posts
  • Version:GM:Studio

Posted 09 February 2012 - 10:06 PM

Could we see the collision event as well?
  • 0

#3 white_boi

white_boi

    GMC Member

  • New Member
  • 44 posts
  • Version:GM8

Posted 09 February 2012 - 10:20 PM

Could we see the collision event as well?


there is no specific Collision Event its in my movement code, here it is:
var fholdd, fholdu, fholdl, fholdr, cc;
// Check the keys
holdd=keyboard_check(vk_down)
holdu=keyboard_check(vk_up)
holdl=keyboard_check(vk_left)
holdr=keyboard_check(vk_right)
// Cancel the opposing keys
if holdu && holdd {
    holdu=0
    holdd=0
}
if holdl && holdr {
    holdl=0
    holdr=0
}




// This is where you may want to add other conditionals which keep you from moving,
// such as if you are using an item, or you are in a menu.
// Just add the conditions to the end of this next "if" line.
// example:
// if (holdd ||holdu || holdl || holdr) && !usingshield {
if chargesword{
if keyboard_check(ord('Z')) {chargecount+=1;image_speed=0;image_index=3;} 
else if chargecount<30{chargecount=0;chargesword=0;usingsword=0;image_speed=0.5;
execute_string('sprite_index=sprLinkStand'+global.facing)}
else if !spinsword{sprite_index=sprLinkSpin; sound_play(Sword_Charge); image_speed=0.5;spinsword=1;alarm[0]=16; aaaa=instance_create(x,y,objLinkSword);aaaa.sprite_index=sprLinkSpinMask}
if chargecount >= 30{
chargecount=30
if holdu and place_free(x,y-1) y-=1
if holdd and place_free(x,y+1) y+=1
if holdl and place_free(x-1,y) x-=1
if holdr and place_free(x+1,y) x+=1
}
}

if (holdd ||holdu || holdl || holdr) && !usingsword
        && (sprite_index!=sprLinkLiftD and sprite_index!=sprLinkLiftU and sprite_index!=sprLinkLiftL and sprite_index!=sprLinkLiftR)  
        && (sprite_index!=sprLinkThrowD and sprite_index!=sprLinkThrowU and sprite_index!=sprLinkThrowL and sprite_index!=sprLinkThrowR) 
        {
its not the whole thing the rest is just sprite correction.

Edited by white_boi, 09 February 2012 - 10:21 PM.

  • 0

#4 thegame

thegame

    Flying Penguin

  • GMC Member
  • 1495 posts
  • Version:GM:Studio

Posted 09 February 2012 - 10:43 PM

Try replacing this
if holdu and place_free(x,y-1) y-=1
if holdd and place_free(x,y+1) y+=1
if holdl and place_free(x-1,y) x-=1
if holdr and place_free(x+1,y) x+=1
with this:
if(holdu && place_free(x,y-1+vspeed))
  y-=1
if(holdd && place_free(x,y+1+vspeed))
  y+=1
if(holdl && place_free(x-1+hspeed,y))
  x-=1
if(holdr && place_free(x+1+hspeed,y))
  x+=1
And this:
if global.roll=true{
  if keyboard_check (vk_up)
        {sprite_index= sprLinkJumpU; speed = 4; direction = 90; break;}
else
    if keyboard_check (vk_down)
        {sprite_index= sprLinkJumpD;speed = 4; direction = 270; break;}
else
    if keyboard_check (vk_left)
        {sprite_index= sprLinkJumpL;speed = 4; direction = 180; break;}
else
    if keyboard_check (vk_right)
        {sprite_index= sprLinkJumpR; speed = 4; direction = 360; break;
    }
    sound_play (choose(sndLink_Roll_1,sndLink_Roll_2,sndLink_Roll_3));

}
with this
if (global.roll) {
  if(keyboard_check (vk_up)) {
    sprite_index= sprLinkJumpU;
    vspeed = -4
  } else if(keyboard_check (vk_down)) {
    sprite_index= sprLinkJumpD;
    vspeed = 4;
  } else if(keyboard_check (vk_left)) {
    sprite_index= sprLinkJumpL;
    hspeed = -4;
  } else if(keyboard_check (vk_right)) {
    sprite_index= sprLinkJumpR;
    hspeed = 4;
  }
  sound_play (choose(sndLink_Roll_1,sndLink_Roll_2,sndLink_Roll_3));
}

Edited by thegame, 09 February 2012 - 10:43 PM.

  • 0

#5 white_boi

white_boi

    GMC Member

  • New Member
  • 44 posts
  • Version:GM8

Posted 09 February 2012 - 11:46 PM

Try replacing this....

It didn't really do anything, you just simplified the code i already had, you see the object as it is does stop when there is something solid! its only when i roll when i go through everything! is there any way i can put so it stops you when you contact ANY solid?

Edited by white_boi, 09 February 2012 - 11:53 PM.

  • 0

#6 thegame

thegame

    Flying Penguin

  • GMC Member
  • 1495 posts
  • Version:GM:Studio

Posted 10 February 2012 - 01:17 AM

I didn't just simplify it... I simplified it and made a small change which I thought was your problem... apparently I was wrong
  • 0

#7 white_boi

white_boi

    GMC Member

  • New Member
  • 44 posts
  • Version:GM8

Posted 10 February 2012 - 01:26 AM

I didn't just simplify it... I simplified it and made a small change which I thought was your problem... apparently I was wrong

oh i see, sorry. well i havent been able to fix it yet... have anyother ideas?
  • 0

#8 Silver Scratch

Silver Scratch

    GMC Member

  • GMC Member
  • 166 posts
  • Version:GM8

Posted 10 February 2012 - 01:30 AM

Did you make the walls solid? Well i'm not good with stuff like that. Try the "place_meeting" function. Example:
if(place_meeting(x,y,Obj_wall))
{
/*
depending of the position, you can put rather hspeed or vspeed to zero.
*/
}
  • 0

#9 white_boi

white_boi

    GMC Member

  • New Member
  • 44 posts
  • Version:GM8

Posted 10 February 2012 - 02:57 AM

Did you make the walls solid? Well i'm not good with stuff like that. Try the "place_meeting" function. Example:
if(place_meeting(x,y,Obj_wall))
{
/*
depending of the position, you can put rather hspeed or vspeed to zero.
*/
}



YES!!! that worked PERFECT!!! heres what i did:
in the Step Event:
if place_meeting(objInvisibleWall.x, objInvisibleWall.y, objInvisibleWall){
    move_bounce_solid(1);   
}

its working like a charm!! thank you once again Silver Scratch!! hopefully the beat will be out in about less than a week! even less if i keep getting the help i'm receiving!!
  • 0

#10 Silver Scratch

Silver Scratch

    GMC Member

  • GMC Member
  • 166 posts
  • Version:GM8

Posted 10 February 2012 - 06:39 PM

Yay! :D !
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users