Set Rigidbody.velocity for an instantiated object


I’m trying to instantiate an object so that it has the same velocity as the player when it is created. However, when I try to implement this, it always spawns immobile, even when the player is moving. Yet, my attempt at debugging shows the player velocity and the instantiated object’s velocities as being the same. (???)

void Update()

            Instantiate(shot, playerPos.position, playerPos.rotation);
            shot.GetComponent<Rigidbody>().velocity = GetComponent<Rigidbody>().velocity;

            Debug.Log("Shot " + shot.GetComponent<Rigidbody>().velocity + " // Sled " + GetComponent<Rigidbody>().velocity);

You need to reference the Instantiated object’s Rigidbody, not the prefab’s.

GameObject shotInstance =  Instantiate(shot, playerPos.position, playerPos.rotation);
shotInstance.GetComponent<Rigidbody>().velocity = GetComponent<Rigidbody>().velocity;