Topic: Bullets spawn from the spawn position and fall down.
Problem: My Bullets fall down when I instantiate it from a Javascript script that is attached to my gun
Theory: I might be typing something wrong or Unity3D doesn’t know how to AddForce on an instantiated bullet
var BulletPrefab : Transform; //What will be shot out
var BulletSpawn : Transform; //Place a empty game object in front of gun, this will act as Bullet Spawn
var BulletSpeed : float = 1000; // The speed in which the bullet flies
var BulletSound : AudioClip; //The sound when a bullet is fired
var ReloadTime : float = 5; //The time it takes to reload a bullet
var MagCapacity : int = 30; //The amount of bullets a magazine can hold
var MagCurrent : int = 30; //The Starting amount of bullets
var NoBulletClick : AudioClip; //The noise the gun makes when there is no more ammo
var ReloadSound : AudioClip; //The reload sound the gun makes, (Recommended it is as long as the reload time)
var IsReloading : boolean = false; //Keep this off, this makes sure that the gun cannot be shot while reloading
function Start(){ //This function makes us start with the maximum amount of bullets we are allowed and tells us that it is working
MagCurrent = MagCapacity;
Debug.Log(MagCurrent);
}
function Update(){
///////////////////////////////////--Shooting--////////////////////////////////////////////////////
if (Input.GetKeyDown("mouse 0") MagCurrent > 0 IsReloading == true)
{
}
else
if (Input.GetKeyDown("mouse 0") MagCurrent > 0 IsReloading == false)
{
-- MagCurrent; //This deducts 1 from our current magazine
audio.PlayOneShot(BulletSound); //Makes a bullet sound
Shoot(); //Starts the function to shoot bullets
}
///////////////////////////////////--No Ammunition--////////////////////////////////////////////////////
if (Input.GetKeyDown("mouse 0") MagCurrent == 0 IsReloading == true)
{
}
else
if (Input.GetKeyDown("mouse 0") MagCurrent == 0 IsReloading == false)
{
Debug.Log("No Ammunition");
audio.PlayOneShot(NoBulletClick);
}
///////////////////////////////////--Reloading--////////////////////////////////////////////////////
if (Input.GetKeyDown("r") MagCurrent < MagCapacity IsReloading == true)
{
}
else
if (Input.GetKeyDown("r") MagCurrent < MagCapacity IsReloading == false)
{
Reload();
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function Shoot(){
var Bullet = Instantiate (BulletPrefab, BulletSpawn.position, BulletSpawn.rotation);
Bullet.rigidbody.AddForce(transform.right * BulletSpeed);
}
function Reload()
{
IsReloading = true;
audio.PlayOneShot (ReloadSound);
yield WaitForSeconds (ReloadTime);
MagCurrent = MagCapacity;
IsReloading = false;
}
Requesting immediate help
Hastebin link: http://hastebin.com/harewacuko.cs