Jump to content


Photo

Collision


  • Please log in to reply
3 replies to this topic

#1 Nicolaibonde

Nicolaibonde

    GMC Member

  • New Member
  • 13 posts

Posted 25 February 2012 - 09:40 PM

I want and object to be deleted when it is under my "obj_hero" how can i do this.
this code doesn't work.
if place_meeting(x,y,obj_hero){
            instance_destroy();
}
it just deletes it when it collides (as expected) ;)

  • 0

#2 thegame

thegame

    Flying Penguin

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

Posted 25 February 2012 - 09:57 PM

So if it is exactly the same position as the hero?
if(x == obj_hero.x && y == obj_hero.y)

  instance_destroy();


  • 0

#3 Nicolaibonde

Nicolaibonde

    GMC Member

  • New Member
  • 13 posts

Posted 25 February 2012 - 11:34 PM

So if it is exactly the same position as the hero?

if(x == obj_hero.x && y == obj_hero.y)
  instance_destroy();

Well that doesn't work, but i dont know why,
side note the object move toward the "obj_hero" when it is close
  • 0

#4 RangerX

RangerX

    GMC Member

  • GMC Member
  • 965 posts
  • Version:GM8.1

Posted 26 February 2012 - 01:30 AM

That code suggestion doesn't work because the obj is destroyed only when its at the exact same position than the hero. This position might be hard to get, especially if the hero is moving.
Anyhow, explain us exactly what's happening in your game. There's an item that moves toward the hero when the later gets near? And when do you want this item to disappear exactly?

If you use things like "place meeting" or again, a collision event, your action (the destroy) will happen as soon as it touches the hero's sprite. if you want to hero to overlap your item a little before the item disappears, have you tried to simply reduce the size of the collision mask of the item's sprite? That should work just fine with a collision event and your item's sprite set to "precise".
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users