Another solution

Why don’t we change the layer of the GameObject to be ignored by the raycasts? Or is it not a good practice? LayersEnum.IgnoreRaycast equals 2. (But this depends on how you configure the layers within the editor I believe)

        void Die()
        {
            this._animator.SetTrigger("DeathTrigger");
            this._hasAnimationPlayed = true;
            this.gameObject.layer = (int)LayersEnum.IgnoreRaycast;
        }
1 Like

Sorry I missed this question.
There are many ways to accomplish the goal of preventing a dead enemy from being picked up in a Raycast. All of them are equally valid…

You can destroy the Colliders
You can Destroy the gameObject altogether (although this would mess with the loading/saving)
You could change the layer
You could do none of these and simply discard the raycast if the character’s health is dead.

1 Like

Isn’t it a bad idea since typically, you would want to still be able to raycast that object to perform some other action on it (like a loot feature) ?
If you directly change the layer of the gameObject, it would then means that you would have to create quite a lot of different layers to handle all the possible actions right ?

1 Like

It would depend on your looting model. For the course, once we get to Inventory, we’ll be placing the dropped loot right on the ground next around Mr. Body. Each of the loot pickups will have their own colliders. If you choose instead to make Mr. Body a loot container, it might make the most sense to modify the CombatTarget to choose between displaying an inventory of dropped items if the character is dead or to attack if the character is alive.

1 Like

This topic was automatically closed after 70 minutes. New replies are no longer allowed.

Privacy & Terms