Question by
tobi9595 · Apr 05, 2021 at 02:41 PM ·
scripting problem
Get velocity of instantiated Prefab
Hello together,
I instantiate the Rigidbody "Clone" from my Prefab "Bullet" to shoot them in my project. I want to get the velocity of every bullet (every instantiation) I shoot, if a collision is detected. In the following my code example:
public GameObject throwstart;
public Rigidbody Clone;
public float bulletVelocity { get; set; } = 1;
...
...
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
Rigidbody Clone2;
Clone2 = Instantiate(Clone, throwstart.transform.position, throwstart.transform.rotation);
Clone2.GetComponent<Rigidbody>().AddForce(Clone2.transform.forward * bulletVelocity, ForceMode.Impulse);
Debug.Log("Velocity Clone Instanz: " + Clone2.mass);
Debug.Log("Velocity Clone Instanz: " + Clone2.velocity);
}
}
With the code above I get the velocity/mass of my prefab (So velocity is always (0, 0 ,0)). What am I doing wrong, how is it possible to get the velocity of every instantiated bullet (Later with collison)?
Many thanks and best regards!
Comment
Your answer
