- Home /
How to enable gravity on prefab after collision?
I have a bullet prefab with gravity disabled when the player fires. I would like to turn on the gravity of the bullets after they collide with an enemy
I have an Attack function in my player movement script that fires the weapon with fire1, and a destroy bullet class on the bullet prefab that deletes bullets after 2 seconds post impact
My OnTriggerEnter function is being used to change the camera when the player enters the boss area, and the OnCollisionEnter function detects ground impact (both on the player movement script)
I thought I should enable gravity to the prefab using the destroy bullet script thats on the prefab, but for some reason I can't seem to disable useGravity in this script
any ideas?
I debugged and saw that I needed OnCollisionEnter in the destroy bullet class.
void OnCollisionEnter (Collision other)
{
if(other.gameObject.tag == "enemy")
{
rigidbody.useGravity = true;
}
}
hope this helps someone else : )