- Home /
Bullets firing Bullets?
I've been trying to get some bullets to instantiate at the barrelEnd position and move forwards towards the player, but it's turned up interesting results. Basically, when i fire a bullet, it moves forwards but then instantiates a new bullet on the bullet i just fired as it travels towards the player. This means that one bullet becomes two,then two bullets become four and it keeps increasing exponentially. This causes a lot of lag and has pretty much stopped my progress. After experimenting with some different ideas, I ended up with a bullet that fired guns, a gun that fired it's barrel and bullets that sit still in the barrel but don't increase exponentially.
I know that the problem is caused because bullets are instantiating on bullets, so that means they'll even spawn on clones of bullets. Those print commands were for debugging stuff, so yea.
#pragma strict
public var PistolBullet : Rigidbody;
public var barrelEnd : Transform;
function Update ()
{
if(Input.GetKeyDown(KeyCode.Space))
{
print ("bbbb");
var BulletInstance : Rigidbody;
print ("vvvv");
BulletInstance = Instantiate(PistolBullet, barrelEnd.position, barrelEnd.rotation);
print ("Debug thingy");
}
}
function OnCollisionEnter (col : Collision)
{
if(col.gameObject.name == "Bullet Time Chamber 01")
{
Destroy(col.gameObject);
}
}
What does this DestroyBullet() function do? Can you post its code?
Are you keeping Space held down ?
Try (Input.Get$$anonymous$$eyUp($$anonymous$$eyCode.Space)) this will only register when you lift your finger up from the space bar. Let me know bud. Cheers. Gruffy
What scripts, if any, are on your bullet prefabs? If your bullets are increasing exponentially, then it's likely the problem lies there.
Alright guys. Problems solved. I just had to tweak the barrel position and move the script onto the gun rather than the bullet.
Now, Time to add a slowmotion feature. This should be fun.
Your answer
Follow this Question
Related Questions
my STFPSC script has errors can anyone help me? 0 Answers
Add Weapon 1 Answer
Networking 0 Answers
Black and white effect 0 Answers