How do I consider Z order for collision checks?

0 favourites
  • 4 posts
  • Hey guys,

    I am currently trying to tell an object to only collide with another object if they are connected on the Z axis.

    This means that if another object is in between those two object on the Z axis, collision should not happen.

    Is there any practical way to handle this? Since I didn't find a nice solution yet I resize the collision polygons of the objects by frame depending on the position which is a very inaccurate and dirty solution.

    Any help is appreciated.

    cheers

  • hey jcstranger, thats a good question ,

    I dont know if there is a better way but ...I would consider keeping in mind the process order of your event sheets.

    Event sheets process commands from top to bottom so basically if you combined this knowledge with turning on and off groups of events you should be able to come up with a solution.

    Or another possibly easier way would be to use Instance Variables, in this case I would use Booleans

    1st ....-Put all of your Collision checked objects into a Family and then assign a Boolean Instance Variable to the Family

    Name it something like "Collision_Enabled"

    Then if you put all of your Collision check Events in a Group on your Event Sheet, you could direct the Z-index equal Collision objects to The Collision Actions in the next Event because Event Sheets process from top to bottom

    The Construct 2 manual entries on Z order are

    -LayerName

    The name of the layer the instance is currently on.

    -LayerNumber

    The zero-based index of the layer the instance is currently on.

    -ZIndex

    Gets the zero-based index of the Z order of this instance within its current layer. 0 is the bottom instance, increasing up to the top instance.

    So..The next step would be to would create 2 Groups of events one controlling the other...You might be able to make this a sub event but it may work better as a separate event...Trial and error will tell which works best

    Group 1 The Z- index Check

    Create the following event and place it within its own Named Group

    for example : "Z-index Check Group"

    This 1st Group event only compares the Z-index of each object and triggers the Boolean Instance Variable per Object BUT only if they are actually colliding..

    This way you save on alot of processor work ..otherwise you will be clogging up the system with unnecessary checks per tick.

    Z-index Check Group Conditions

    -->Object or Family 1--> on Collision with Object or Family 2
    --> System ->Compare 2 Variables-> Object 1 Zindex = Object 2 Zindex
    Actions
    --> System->Turn on Group "Collision Actions"[/code:2o8ncrox]
    
    Next... Event Group 2 
    
    Actual Collision Actions
    
    Create another Event and place it within its own Named Group
    For example : "Collision Actions"
    This Group handles the actual Events that happen if the Z-Index proves equal per object but only if its turned on by the first event group ie  only if the Objects Boolean Variable is Triggered  TRUE by the first z-index check Group
    
    Collision Actions Group Conditions
    
    [code:2o8ncrox]-->System-> For each Object 
    -->Object->Is Boolean Instance Instance Set ("Collision_Enabled")
    Actions
    --> Here is where you would place any actions that are related to the triggered Collisions[/code:2o8ncrox]
    
    ------------------------------------------
    This should be all that is required..I know it sounds complex but if you follow the steps it should work
    providing I didnt miss or forget anything
    
    Hope that Helps
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • hi mystazsea,

    thats a very detailed answer, way more than i was hoping for.

    I will try out your approach and let you know as soon as i have something (or not).

    thank you very much.

  • so i finally figured out a solution that works for me.

    in my game there is endless content randomly generated and scaled to 0 (destroyed).

    besides, the player can also move stepwise (X pixel per touch)

    currently, every second one new object is generated that contains 4 obstacles that can collide with the player, then they scale to 0.

    what i do to solve the collision problem is that i set the new object and obstacle instance to a new layer every second.

    this makes up to 18 layers. now, when i move my player, is substract it by one layer, else it also adds 1 layer per second.

    this way i can check if the player position is on the obstacle position.

    if both variables (player and obstacle) have the same "layer" variable, i check for collision.

    i am not sure if this is a dirty solution performance wise, but it is at least very precise.

    thx again for helping

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)