Quantcast
Channel: Questions in topic: "gun"
Viewing all articles
Browse latest Browse all 592

Rigidbody bullets won't spawn at gun barrel...

$
0
0
This is my first project in Unity and I am trying to create a simple FPS game. My problem is that no matter what I try, my rigidbody bullets won't spawn at the designated object but instead, somewhere bellow (relative to the gun). Here is the shooting script I created... public GameObject Spawn; public GameObject BulletPrefab; public GameObject Sound; public GameObject Gun; public ParticleSystem Emitter; public Light GunLight; public float EmissionTime; public float Recoil; public float BulletImpulse; public Camera cam1; public Camera cam2; float timer; void Start () { Emitter.enableEmission = false; GunLight.enabled = false; } void Update () { if (Input.GetButtonDown("Fire1") && Emitter.enableEmission == false && !Input.GetButton("Fire3")){ timer = 0; GameObject newbullet = (GameObject)Instantiate(BulletPrefab,Spawn.transform.position,Spawn.transform.rotation); Instantiate(Sound,transform.position,Camera.main.transform.rotation); newbullet.rigidbody.AddForce(newbullet.rigidbody.transform.forward * BulletImpulse,ForceMode.Impulse); //newbullet.transform.position = new Vector3(Spawn.transform.position.x,Spawn.transform.position.y,Spawn.transform.position.z); Emitter.enableEmission = true; GunLight.enabled = true; } if (Emitter.enableEmission == true){ timer += 80*Time.deltaTime; if (timer > EmissionTime){ Emitter.enableEmission = false; GunLight.enabled = false; } } } Sorry for the long post, thank you for your time.

Viewing all articles
Browse latest Browse all 592

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>