I
I
IslamKarimov20182021-01-26 09:07:44
Unity
IslamKarimov2018, 2021-01-26 09:07:44

How to properly check for collision in Unity?

I'm trying to make a collision of two 2D objects in Unity. I do not use Rigidbody, but I calculate everything myself using BoxCast (on some CircleCast objects). The problem is this: when two moving objects collide, both say that they collided. And it turns out that the first object handles the collision and reduces health, and the second object handles the collision and takes health away from the first object.
How can it be more intelligently implemented so that collision processing is performed by one of the collided objects, and not both?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dollar, 2021-01-26
@dollar

It is necessary to logically accept and then observe one of two conditions:
a) Objects with health take care of their own health. And no other entity but them has the right to do so.

spoiler
То есть в коде снарядов нельзя писать код, уменьшающий здоровье других объектов.

b) Only weapons and projectiles can reduce the health of other objects.
spoiler
То есть в коде объектов со здоровьем нельзя писать код, уменьшающий их собственное здоровье.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question