- Home /
 
 
               Question by 
               DoctorChar · Apr 18, 2017 at 09:52 AM · 
                rigidbodyprefabfpsshooting  
              
 
              Gun Rotation Problem
No bullets are going up or down.
Here is my script for firing. (Bullet_Emiter is rotating fine.)
 GameObject Temporary_Bullet_Handler1;
                             Temporary_Bullet_Handler1 = Instantiate(Laser, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject;
 
                             Rigidbody Temporary_RigidBody;
                             Temporary_RigidBody = Temporary_Bullet_Handler1.GetComponent<Rigidbody>();
 
                             Temporary_RigidBody.AddForce(transform.forward * Bullet_Forward_Force);
 
                             Destroy(Temporary_Bullet_Handler1, 3.0f);
 
              
               Comment
              
 
               
              Answer by SohailBukhari · Apr 18, 2017 at 11:17 AM
Rigidbody.velocity changes the velocity in an instant while AddForce applies force on an updated basis based on how you use it. Basically Both are force mode.
  ForceMode.Force == Force apply per second  
  ForceMode.Impulse == Force apply per frame
 
               So it would be better in your case use the rigidbody velocity instead of Force.
 GameObject Temporary_Bullet_Handler1;
 Temporary_Bullet_Handler1 =
 Instantiate(Laser, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject;
 Rigidbody Temporary_RigidBody;
 Temporary_RigidBody = Temporary_Bullet_Handler1.GetComponent<Rigidbody>();
 //here use the velocity
 Temporary_RigidBody.velocity = Temporary_RigidBody.transform.forward*Time.deltaTime*Bullet_Forward_Force;
 Destroy(Temporary_Bullet_Handler1, 3.0f);
 
              Your answer
 
             Follow this Question
Related Questions
Issue with Bullet Movement shooting 0 Answers
Prefab Shooting 0 Answers
FPS rigidbody bullets not moving to center of screen 0 Answers
Instantiating a prefab as a component type? 2 Answers
Why do I get: "Cannot cast from source type to destination type"? 1 Answer