Multi-Resolution Game Development With GameBuilder Studio Check it out!
NEW Version 0.9.7 has arrived! New Blazing Fast Particle Engine & More Game Actions. Check it out
Help with Collision Detection over time
  • I am hoping someone can help me with my dilemma that I am having with my project.  

    Currently I have a series of "targets" and "enemies" and the "enemies" will randomly aim towards any of these "targets" using the find in range method. This works (apart from some kinks that need sorting) but if one of the "enemies" passes over one of the "targets" en route, then the collision logic I currently have, is activated .

     What I am trying to achieve is only activate the collision logic if the "enemy" is on the "target" for a period of time. However the rule map condition does not see to have such an option and I also tried to Count the collision occurrence but it appears that it only occurs one time

      Can someone please point me in the right direction on how to do this. 

    ** EDIT ** Update on this 19/05/2016

    I have tried to use the spatial that is stored from the find in range action to then compare this to the current collideespatil , this is has been done as part of the rules map which is checking for a collision with the filtered enemy.  This maybe the way to do this but when applying this extra logic to the rule component, it does not work and the target objects it is applied then are not showing on the scene/level. 

     I will continue to look and work on this but if anyone has any suggestions it would be appreciated.

      


    Thanks

    TimCS
  • 9 Comments sorted by
  • I was wondering if it was possible to only have the enemy react to the target it is moving towards and so if it does pass over another object that is a target it does not have any affect but , I am unable to work this out.

    If anyone has any suggestions on how to achieve this I would appreciate it.

    Thanks

    TimCS
  • @TimCS If you don't want an object to simulate with another object then you need to turn it into a sensor. There is an isSensor flag on each collision shape on a collision spatial.
  • @Lavon

     All objects are set as sensors so the targets and the enemies are sensors but the targets are filtered to all collide with the enemies as the enemies are under one group of the filter and the targets are under another group. 
     
      Hence my problem as , as soon as one of the enemies passes over  a target heading towards another the collision detection occurs. 

    So to put this in to perspective the targets are under a filter group called "target"  and are set to collide with the enemies group which is "enemies" , the enemies are set under a filter group called "enemies" and they are set to collide with the "target" group and the "player" group.



      
  • @Lavon

        Just to clarify what is happening, the enemies , at times, will "pass over" or go over one of the targets en route to the target it is aiming for. As both the enemy and the target are filtered by the collision filter on each object , when the enemy does pass over or crosses paths with the target the logic I have placed will start. 

      So because the enemy has the spatial of the target that it is aiming for , I have tried to add further logic to check if the spatial that it has collided with is the one that is is aiming for. However my attempts at trying this have failed. I have tried both the expression and property comparison through the rules component along with the collide with target condition but these do not work.

      I hope I have made matters a little clearer here on what is happening, if not let me know and I will try and provide further examples

    Thanks

    TimCS
  • @Lavon

      Any further thoughts on this since my last post ? I am still not getting anywhere with this.
  • Hi TimCS, not sure what you finally want to do with the enemys and targets. But in general I would recommend to work with the StateMachines (like in the HungryHero Tutorial) as often as possible, because I noticed myself that with a bunch of RulesMaps you will come to the point where they get in conflict with each other just because my mind couldn't comprehend all the possible "what happens when..." combinations.

    So in you case, you could do three States for the enemys: "search_target_state", "walk_to_target_state" and maybe "explode_state" (or a fight_state or whatever you want to do with enemys and targets). That would prevent, that the enemy does operations from one state while in another (like exploding while on the way to a target).

    Or: instead of exploding/fighting in contact with a target, you could store the targets coordinates and spawn a thrid object (like destination) close to the target and use the "move to" and "collide with" actions with the destination object.

    Have a look at my project in this post. Sadly there seems to be a bug in GBS, where it caches collisions. So it is not working 100% perfect. There is a catcher-object choosing between several preys, then it moves to a selected one with the help of a closetotarget-object and on collision with the specific target, it sould disapere and the catcher should reset. To prevent other Preys from disapering on collision, I did use a "cought"-Property on the selected one and the death-on-collision RulesMap only works if the cought-flag is also set. Maybe that was all you needed :)
  • @TimCS I am looking into this...
  • @TimCS i believe I understand the nature of your problem. Although it would be easier with a sample project. 

    Here is my suggestion. If you have enemies that are all over your scene and they can end up overlapping a target but not the target they are intended for then you need some way to check if the target that an enemy is headed for matches when the collision trigger happens. So in the latest build you now have more collision information to pull from. 

    So If the enemy is doing the searching and the enemy is the object that determines which target to lock onto then it needs to store a unique name or id or some property that identifies the target it has just locked onto. You can now access components and properties on the two objects involved in a collision. So if the enemy finds a target it should store that targets name or id on itself. Each target should have some unique number or id assigned to it on creation. Then when a collision happens you check the stored identifier to match with the id of the collider on the new CurrentCollisionData property that is now available to you. If they match then your detroy logic can execute. The new collision event information is covered here in this video 

    Now the tricky part is you want to determine if a collision happened or rather if you are currently overlapping a target for a certain amount of time so you can't use the Collision Event condition to trigger your logic directly you will have to use the Collision event condition to set a Boolean flag to true on collision start and false on collision stopped. You also need the collision event data that is present only when a collision event condition is triggered on a Rules Map so you will also need to store the unique identifier of the object you collided with when the collision started because that information will be cleared by the time you check the collision flag later on after some time. So in a separate Rule Map when the collision started is triggered you set the boolean, the unique id, and also start a timer that will set another Boolean property after a set amount of time. (Make sure "Run to Completion" is unchecked) Call the property whatever you want. 

    So now your main Rule Map Component that needs to determine destruction will check all these properties: 

    Am I currently overlapping (colliding)
    Am I currently overlapping with the correct target
    Am I ready to destroy (Boolean)

    The two Boolean flags for overlapping and readyToDestroy need to be reset to false on a separate Rules Component if the collision stops at any point. Also clear the current target unique Id.
  • @Cavaron @Lavon

     My appologies for not coming back  sooner to your replies things have got a bit out of hand :( . Thank you both for your replies , @Cavaron, I do not seem to see your project you have mentioned that is in this post.

    @Lavon

        Thank you for your reply also and very helpful I will look into this as well.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

Tagged