Layer-collision question

  • Hello!

    I'm working on a game where the player can fire a gun at incoming tanks:

    As you can see, the tanks go 'up and down' the hills. I move them on different layers when they reach a Y position on a layer:

    Now, this works. However, when I fire the gun by touch I'm having trouble making it 'pseudo 3D'.

    The shell has bullet behavior and the shell comes from underneath traveling towards last TouchX and TouchY. When it hits a tank, tank is destroyed.

    However, currently you can hit the tanks when they're behind the hills. I was able to program something to prevent that from happening, e.g. you can only hit Tank if Tank is on layer 'x' and that kindoff works.

    Problem is, when the tank is only half behind the hill you can't hit it (obviously) because the layer condition wasn't met yet. It's only met when the tank is fully 'up' the hill and switches from layers.

    Does anyone have any suggestions how to tackle this?

    Thanks!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I don't quite understand your layers system. What you can do is check if there is any hill sprite in front of the tank at the moment of collision. With tanks and hills on different layers this can be tricky but you can try something like this:

  • Hi dop2000, thanks for your reply.

    Well the layers are as follows:

    Dune1 just has the first 'Dune1' sprite on it.

    Dune1Tanks is the layer where the Tank is moved to when it reaches a certain travel distance.

    Dune2 has the second 'Dune2' sprite on it.

    Dune2Tanks is the last layer the Tank is moved to.

    The Tank is moved to layers to make it go 'up' and 'down' visually.

    Anyway, I tried your sample, but I think it is too complicated for me. Or at least, I don't quite understand it. Do I need to implement this code for each Dune sprite? As it goes up and down on two 'Hills'.

    I also thought of and experimented with using a 'hitbox' sprite that is pinned to the Tank, had some ideas for it, but in practise I got so confused on how to implement it that I gave up for the moment.

    Thanks again.

  • If you have multiple sprites for dunes, add them all to a family Dunes, and then in my code example replace "Hill" with "Dunes".

    What my code does - when a tank is hit, it checks if there is any hill/dune sprite in this point. And if this hill is on a layer higher than tank, or on the same layer with tank, but above the tank on z-axis, then the hit is cancelled. (because the tank is hidden by the hill)

  • Hi Stan,

    Thanks.

    I finally managed to fix it by using a collision sprite. When the tank spawns, the container also creates the collision sprite.

    It grows along with the tank's width. I set the sprite just above the dune. I allow collision detection as soon as the first part of the tank peeks above the dune.

    I also put the collision sprite to the other layers so it travels along with the tank. And repeat for the second dune.

    If that makes any sense.

    I tried your sample but it was either hit or miss; I think I didn't have much choice to make sure only a part of the tank gets hit, the part that is visible over the dune.

    Thanks for thinking with me.

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