Is there a way to mask physics?

Hi, I’ve searched forum and I couldn’t find my answer (maybe bad search keywords)
here is the situation, imagine game like Brick Breaker Star (attached photo) there is one power-up that makes the ball break bricks and go through the whole bunch of them and destroys them but still reacts to the borders. now in my case I have a ball works by physics and gets this power-up , so i need temporarily detect collisions and collisions won’t affect on the ball velocity except specific objects (like borders) in that case physics should be applied.
what I was looking for was masking physics like raycasts in runtime, or enabling/disabling layer masking at runtime.

3268239--252333--Capture.PNG

If there is no solution for that I was thinking to use raycasts to predict collision ahead of time and disable those object collider which I don’t need collision to happen! this way I already have access to gameobject without collision happening

Can’t you use Layers for this? Unity - Scripting API: Physics.IgnoreLayerCollision

Why not use a trigger instead? avoid all the hassle. When the ball enters the block trigger, you already know the angle it will reflect with Vector3 Reflect and you can easily work out by the balls velocity and position, which side of the brick it hit. You have all the info you need to easily bounce. You don’t need true collisions.

Even if you did want weird shapes that would justify a physics engine, you can query penetration these days too, and get a new ball angle/velocity that way too. All you need are two colliders somewhere.

Truth be told a physics engine is way overkill for this kind of thing, but if you want to use it, then it’s perfectly possible without any hacks.

1 Like

I will try it but I think using that will skip OnCollision completely so I won’t know what objects the ball had passed through

You mean then I manually handle the physics by using addForce? I was hoping some easier way for it.

No, you just set a new velocity once when you receive the ontriggerenter callback. If this is too advanced for you I would suggest learning more about Unity and I cannot help you, best of luck though :slight_smile:

1 Like

Thanks for replies, I think there is no such thing as Masking Physics based on layer or tag for a period of time in runtime, and using triggers required a lot of changes in my game, so I decided to use raycast and detect objects before collision and handle them (mostly destroy them before collision happen) and keep objects I needed them to affect on my physics.