Weird behavior when projectile hits target and becomes child.

Whenever my projectile hits something, I have a script that allows it to stick to the object it collided with. For some reason, the hit object always moves a little bit towards the direction the projectile came from.

Gif of what is happening here: WeirdBehavior Gif

Here is the method that I’m using in script that is on the projectile:

    void TridentStick(Collision2D col)
    {
        myRigid.velocity = Vector2.zero;
        Destroy(gameObject.GetComponent<Rigidbody2D>());

        PROJECTILE_DEPTH = Random.Range(minDepth, maxDepth);
        Debug.Log(PROJECTILE_DEPTH);
        
        col.transform.Translate(PROJECTILE_DEPTH * -Vector2.right);
       
        transform.parent = col.transform;
        
        Destroy(gameObject.GetComponent<Collider2D>());
        isHit = true;



    }

Any Idea what could remedy this behavior?

Hello, that happens because you are moving the position of the col gameObject.

Here’s my solution

void TridentStick(Collision2D col)
     {
         myRigid.velocity = Vector2.zero;
         Destroy(gameObject.GetComponent<Rigidbody2D>());
         PROJECTILE_DEPTH = Random.Range(minDepth, maxDepth);
         Debug.Log(PROJECTILE_DEPTH);
         
         //col.transform.Translate(PROJECTILE_DEPTH * -Vector2.right);

         transform.parent = col.transform;
         transform.localPosition = transform.localPosition + (PROJECTILE_DEPTH * Vector3.right);
         
         Destroy(gameObject.GetComponent<Collider2D>());
         isHit = true;
     }