How do I change collision detection based on layer?

0 favourites
  • 5 posts
From the Asset Store
Simplistic hyper-casual game with nature elements. Tap to switch between the 4 elements and reach a better score.
  • I am making a pinball game. In this game there is an 'upper track' that I intend the ball to go on. I have placed this 'upper track' on a layer above the 'machine' layer that the ball usually interacts with. I have placed a sensor at the entrance to the 'upper track' and one at the exit. The entrance sensor checks the velocity of the ball and the layer it is on. If the ball is going up and is on the 'machine' layer, then sensor moves the ball to the 'upper track' layer. If it is going down and on the 'upper track' layer, then the sensor moves the ball to the 'machine' layer. This is all working properly.

    The bug is that when I move the ball to the 'upper track' layer, it still collides with the 'machine' layer. When I disable the 'machine' layer's physics, then the ball collides with nothing. The ball does not collide with the 'upper track' layer collision bounds even when on the 'upper track' layer.

    Thank you for you time.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Unsure if there is a built in way. But you can use a family if you have purchased or just call a function each time your ball goes from 1 height to another. have the family (or function) turn collision off for the items you can no longer hit and on for the ones you can.

  • The physics behavior has the option to enable/disable collisions with object types. This however (sadly) cannot be done per instance.

    One way of doing it would be to entirely disable physics for all objects on the lower layer (which does work per instance). You can pick these objects with the "pick objects by comparison" and pick all objects that are on the same layer as the ball. This will not work if you plan on having multiple balls on different layers at the same time.

    I cannot go more specific than this since I do not know how you set everything up, but this should give you a general idea.

  • The physics behavior has the option to enable/disable collisions with object types. This however (sadly) cannot be done per instance.

    One way of doing it would be to entirely disable physics for all objects on the lower layer (which does work per instance). You can pick these objects with the "pick objects by comparison" and pick all objects that are on the same layer as the ball. This will not work if you plan on having multiple balls on different layers at the same time.

    I cannot go more specific than this since I do not know how you set everything up, but this should give you a general idea.

    This was my original solution, but has the draw back you stated. I have gone to a work around attempt. I am moving the ball physics 1000 px to the right when it hits the sensor and leaving the gfx in place so it looks like it is on the upper track. It's buggy but it's progress. :)

  • Report of progress

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