- Home /
Weapon Instantiate Problem
So I have a script for a weapon that can shoot multiple bullets at once, but there's always 1 bullet that stays at the same place, even if it's only 1 bullet at a time.
Edit: I already removed the "S", didn't fix it
Here's the script:
Answer by unity_ek98vnTRplGj8Q · May 19, 2020 at 03:13 PM
You are trying to grab the rigidbody of the bullet before you spawn it. Move line 25 where you grab the rigidbody of Bullet2 to right after the Instantiate() call so that it actually refers to the rigidbody of the spawned bullet. Instantiate makes an entirely new game object, so the rigidbody that you want doesn't even exist until you call instantiate.
Also a note on lines 27 and 28... the x, y, and z values of a rotation aren't angles. If you want to add a random angle to a rotation like you are trying to do, use rotation.eulerAngles.x, y, or z instead as these actually refer to the angles of rotation around each axis. The values that you see for x, y, z rotation in the inspector are actually these euler angles.
Your answer
Follow this Question
Related Questions
Instantiating a prefab as a component type? 2 Answers
Instantiate prefab to the parent 2 Answers
Bullet always facing the sky. 3 Answers
Can't instantiate a rigidbody 1 Answer
Instantiated Bomb Not Exploding 1 Answer