Destroy both Collided objects

TangoDownStudiosTangoDownStudios Member Posts: 46
edited November -1 in Working with GS (Mac)
I have a bullet that hits a target, on collision both objects are ruled destroy themselves. The problem is that when the bullet hits the object the object recognizes the bullet hit it, destroys itself and when collision detection is performed on the bullet there is no object and so the bullet goes on its merry way not knowing it hit something. If I set a timer to fix this situation (e.g. not allowing the object to destroy itself for 0.1 seconds etc...) it introduces the problem of more than one bullet being destroyed if they hit in rapid succession.

I have multiple bullet/targets on the screen at the same time. How would I make it so these spawned bullets destroy themselves AND their targets (spawned too)

Comments

  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    you could do something like wheb bullet overlaps with object change bullet alpha to zero, after 0.2 secinds run to compeletion checked destroy bullet

    then in the objec when object overlaps with bullet destroy
  • TangoDownStudiosTangoDownStudios Member Posts: 46
    GsLover said:
    when bullet collide with actor destroy?

    _________________________________________________________________________________

    Just Trying To Help :)

    What exactly do you mean by this?
  • SlickZeroSlickZero Houston, TexasMember, Sous Chef Posts: 2,870
    Have a rule in the bullet when it collides with the enemy to destroy the bullet. And in the enemy have a rule that destroys it when it collides with the bullet.
  • TangoDownStudiosTangoDownStudios Member Posts: 46
    JohnPapiomitis said:
    you could do something like wheb bullet overlaps with object change bullet alpha to zero, after 0.2 secinds run to compeletion checked destroy bullet

    then in the objec when object overlaps with bullet destroy

    JohnPapiomitis said:
    you could do something like wheb bullet overlaps with object change bullet alpha to zero, after 0.2 secinds run to compeletion checked destroy bullet

    then in the objec when object overlaps with bullet destroy

    This introduces the problem of multiple bullets being destroyed upon rapid succession of collisions. I only need the initial collided bullet to destroy the object.
  • TangoDownStudiosTangoDownStudios Member Posts: 46
    SlickZero said:
    Have a rule in the bullet when it collides with the enemy to destroy the bullet. And in the enemy have a rule that destroys it when it collides with the bullet.

    This is how I have it set up now, the collision will work for whatever object is checked first, then the second object will no longer register a collision because the first object has been destroyed
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    TangoDownStudios said:
    This introduces the problem of multiple bullets being destroyed upon rapid succession of collisions. I only need the initial collided bullet to destroy the object.

    then just put a attribute to detect when the bullets alpha is 1,. Say you call it bulleton. Have a rule in the bullet when alpha=1 change bullet on to1, then in ther otheriwse section change bulleton to 0. and only have the object destroy open collosion with the bullet when bulleton=1

    that way it wont get destroyed by a invisble bullet per say.
  • TangoDownStudiosTangoDownStudios Member Posts: 46
    I see what your saying, but this will cause either the bullet to become 'bulleton=0' before the wall runs its collision detection, or the wall will get destroyed and bulleton will stay 1
  • SlickZeroSlickZero Houston, TexasMember, Sous Chef Posts: 2,870
    That should work. I'm working on a game right now that uses a machine gun, and in the bullet I have a rule that says when it collides with the enemy, to add to the bullet count (takes more than one bullet count to kill my enemy) and then destroy the bullet. Then i have a rule in the enemy that gets hit, when bullet count reaches a certain amount, to destroy the enemy.

    In theory, it should be working. You may try setting up an attribute that when the bullet collides with the enemy to add to the bulletcount attribute, when that count reaches a certain number to destroy that enemy. Even if that number is 1 bullet. Give that a try?
  • TangoDownStudiosTangoDownStudios Member Posts: 46
    Johns logic was a bit to take in, I may retract my prior post if it works. I think the logic works, I'm working on it. I'm just not reediting the post right now... gimmi a sec...
  • TangoDownStudiosTangoDownStudios Member Posts: 46
    Okay, the logic is working out like this:

    I have my bullet object moving through the scene
    I have my wall object standing there
    Bullet hits wall object
    Wall registers its been hit and destroys self
    Bullet does not register it hit a wall because wall has been destroyed
    Bullet travels on

    I set a value in bullet to change as the bullet hits a wall but since the wall is never detected this value is useless

    I can set a value in wall to go on when it gets hit will a bullet (WallDestroyed=1 e.g.) and will destroy itself over say... 0.1 seconds. But bullets hitting it before it gets destoyed will die too.

    I would have to set a global variable to check if the wall a bullet is hitting has been hit already or not. And I don't know a good way of doing this

    Basically I want to know how you would do what you recommended john:

    "only have the object destroy open collosion with the bullet when bulleton=1"

    How does the wall know when bulleton is 1?
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    try change both alphas to 0 on both the wall and bullet, then have a timer in both upon collosion after 0.1 seconds run to completeion checked, destroy in both.

    then just make sure you only have collosion occur when both alphas are 1. Youll need a wall on attribute for the wall as well. changing wall on to 1 when alpha=1 otherwise change wallon to 0

    edit: for your question how does it know when bullet on is1. in the rule that has when object collides with bullet destryo, have the rule when bullet collides with object AND bullet on=1 destroy. and if you need to add the extra rule for the wall the rule should be when bulleton=1 and wallon=1 and object collides with bullet destroy.

    try the first way first with those rles, withouth adding the extra attriubtute for the wall and such and see if that works first
  • SlickZeroSlickZero Houston, TexasMember, Sous Chef Posts: 2,870
    If you have a rule in each different actor to be destroyed when colliding with the other, it should be working. If one collides with the other, they both should register that there was a collision, because one would not destroy if it didn't know it had collided with the other. If it's not, then something is going on that shouldn't be. But what that is, I don't know. Maybe post a screen shot of your rules?
  • TangoDownStudiosTangoDownStudios Member Posts: 46
    If I do that, then the walls alpha will start changing before the bullets collision detection is scanned, and since the walls alpha will have changed it will still not work.

    plus this introduces the problem of the bullet checking the walls alpha, and vice versa
  • SlickZeroSlickZero Houston, TexasMember, Sous Chef Posts: 2,870
    Sorry. John and I are talking about 2 different methods here. I'll let him set it straight since he is the more experienced one.
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    try both what i and slick are saying. its just a mtter of playing around til u get it right. This happens alot certain colloisoin/attribute triggers occur faster then others, its just a matter of adjusting till it works. if u want u can send me the project and ill look at it, thats up to you though

    my emails papiomitis at yahoo dot com

    also a screenshot of the rules would help
  • TangoDownStudiosTangoDownStudios Member Posts: 46
    Yea slickZero, I see what you mean. I made a test project and the collision works both ways. I'm looking into whats fubard up in my game project right now
  • TangoDownStudiosTangoDownStudios Member Posts: 46
    I'm sending you teh project john.
  • TangoDownStudiosTangoDownStudios Member Posts: 46
    Collision detection works fine if the destroyed wall just gets destroyed. But I want it that when the wall gets destroyed it emits bullets in all directions. If I make it do that then the bullet that hit the wall does not get destroyed for some reason
Sign In or Register to comment.