[Solved] Child of the parent acting like him [closed]


So this seems pretty much messed up situation here. First of all I would advice you to read answers from here and here to get an Idea of whats happening in your game.

Now lets try to solve the issue based on what information you have shared in your question. I assume that the magnet object (which get attracted due to big sphere) has tag “magnet” so the following code in your OnTriggerEnter() method is decreasing health when your sphere collider collides with it:

if(col.gameObject.tag == "Magnet")
{
    cur_Health -= 1f;
    float calc_Health = cur_Health / max_Health;
    SetBar (calc_Health);
}

If you don’t want to decrease your health when you pick up magnet objects, remove this code.

Now coming to this part of your question:

Now the problem is that I have a health script so when the player
touches any object with his body he loses health

Triggers are caused by all child colliders when rigidbody is attached to parent object. So to solve this issue:

  1. Add a new layer from Tags and Layers and name it “Magnet”.
  2. Now go to Physics Manager and configure Layer Collision Matrix to set magnet layer only collidable to itself like this:

enter image description here

  1. now set this layer to both sphere object (child object of player) and the magnet object which triggers the magnetic affect.

Hope this will solve your problem.

2

solved Child of the parent acting like him [closed]