Keep rotation when changing parent in Unity 3D

Hello, I’m trying to implement arrows. Every frame the arrow changes its rotation depending on its velocity, but when it hits something and I try to attach the arrow to the object rotation goes wrong. I’m sure that the problem occurs when changing parent and I tried everything without result. This is the script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Arrow : MonoBehaviour
{
    private Rigidbody rb;
    private bool hit;
    private Quaternion startingRot;

    void Start()
    {
        rb = GetComponent<Rigidbody>();
        hit = false;
        startingRot = transform.rotation;
    }


    void FixedUpdate()
    {
        if (!hit && rb.velocity.magnitude>0)
        {
            transform.localRotation = Quaternion.LookRotation(rb.velocity);
        }
    }

    private void OnTriggerEnter(Collider other)
    {
        hit = true;
        rb.constraints = RigidbodyConstraints.FreezeRotation;
        transform.SetParent(other.transform, true);
        rb.isKinematic = true;
        rb.velocity = Vector3.zero;
    }

}

This was an interesting problem (the video-clip was a very good demonstration). It seems like you can’t re-parent a rigid body without getting some weird behavior. I tried several things, like disable the rigid body and re-parent first in the next frame, and so on, but it still didn’t work.

The only solution that works for me is to remove the rigid body before re-parenting.

        Destroy(rb);
        transform.SetParent(other.transform, true);

If you don’t like the idea of removing behaviors in run-time you could have a second copy of the arrow, without the rigid body and simply replace the original arrow with the copy.

Good hunting!