- Home /
Figured it out! Bullets collision detection was large enough they collided between barrels and died on spawn.
instantiate works on one but not other object
Hello all!
I'll try to be brief. I have a turret, consisting of a cockpit (with a "fire control" script on it), and two barrels with "Shooter" objects. When the turret sees a target, fire control will send a "fire" message to each shooter, firing a bullet. Relevant part of firing script :
var fireShot : FireShot = turret.GetComponent(FireShot);
projectileSpeed = fireShot.shotSpeed;
fireShot.fire();
Debug.Log("Fire a bullet?");
Now, here is the actual firing script in the shooter :
var ammo : GameObject;
var strength : int = 10;
var shotSpeed : float;
shotSpeed = strength * 10;
function fire(){
fwd = transform.forward;
shot = Instantiate(ammo, transform.position , transform.rotation);
Debug.Log("Just'made' a shot");
shot.rigidbody.AddForce(fwd * 500 * strength);
}
My issue is I have a new bullet type that doesn't work. I had used cube shaped bullets with a rigidbody and a few scripts on it, collider, etc. I also made a second, newer "bullet" which was a plane with a bullet texture, with the same scripts and rigidbody, and a sphere collider instead of a mesh one.
I wanted to change out the "ammo" objects on my turrets, and here were the results :
If BOTH shooters are firing cubes, they both fire. If one shooter is firing cubes and one is firing plane bullets, they both fire. If both shooters are firing plane bullets, they do not fire.
Please help!
Cheers, Marcin
And I should add, that both debug.log statements are recorded no matter the way I set up bullets between shooters.
What do you mean by "they do not fire"? You can't see the bullets, or they really are not fired at all? Put a debug.log in the bullet script if you are not sure - maybe they're being fired but are not visible
Good thinking. I was assu$$anonymous$$g they weren't being fired at all since they did not show up in the hierarchy. I put a debug in the bullets awake function, and they do appear to be actually spawning.
Do your turrets fire multiple shots at once? I mean, are there many bullet instances alive at the same time?
It is two bullets, one for each barrel of the turret, that fire simultaneously.
Follow this Question
Related Questions
Instantiating prefabs, when there is nothing 2 Answers
Adding Imperfections? 1 Answer
How to find and remove the last child of parent? 1 Answer
Checking if object intersects? 1 Answer