- Home /
 
               Question by 
               connorwforman · Nov 15, 2017 at 11:19 PM · 
                scripting problemprefab  
              
 
              rb.AddForce (transform.forward * BulletForce) has issues.
I wrote a prefab shooting script, and when I click the LMB, the bullet instantiates and then falls to the ground, and rolls forward. When I quickly double-click, the bullet shoots forward. I have adjusted the speed, and mass, and that has no effect. What is the problem?
 public Rigidbody rb; 
 public float BulletForce = 100.0f; 
 public GameObject Bullet; 
 
 void Update () {
         if (Input.GetButtonDown ("Fire1")) {
             Instantiate (Bullet, BulletSpawn.transform.position, BulletSpawn.transform.rotation); 
             rb.AddForce (transform.forward * BulletForce); 
 
 
         }
     }
 
               Comment
              
 
               
              Answer by shadowpuppet · Nov 15, 2017 at 11:32 PM
Not sure what is wrong unless the buttondown instantiates the bullet but when the bullet is instantiated the button is already down? Here is a bullet script I use.Rockets actually but same thing
 using UnityEngine;
 using System.Collections;
 
 public class robotBullet : MonoBehaviour {
     public GameObject rocket;
     private int throwDistance = 1000;
 void Update(){
 If(Input.GetButtonDown ("Fire1")){
 Shoot();
 }
     void Shoot(){
         GameObject projectile =Instantiate(rocket, Muzzle.position,Quaternion. identity)as GameObject; 
         projectile.GetComponent<Rigidbody>().AddForce (transform.forward *throwDistance);
         
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                