- Home /
gun fire p90`s how to spawn gun fire
hey im wesley i have my guns 2 p90`s they shoot bullets that works But i dont know how to get the fire out of the gun as it shoud be is it a particle that i can make or what??. tel me sombody how to do this i have alreddy a script that i hope that works for spawning the fire when i press down my left mouse button the guns fire So can i use this script also? with little changes
the script of my p90`s Bullet.
var projectile : Rigidbody; var speed = 2000;
function Update() { if( Input.GetButtonDown( "Fire1" ) ){
var instantiatedProjectile : Rigidbody = Instantiate( projectile, transform.position, transform.rotation );
instantiatedProjectile.velocity = transform.TransformDirection( Vector3( 0, 0, speed ) );
Physics.IgnoreCollision( instantiatedProjectile. collider, transform.root.collider ); } }
thanks wes
http://www.youtube.com/watch?v=yE3zZPdQRas&feature=related
Is that what you mean?
Answer by FLASHDENMARK · Dec 30, 2010 at 07:55 PM
You could try:
var Bullet : Transform;
function Update () {
if(Input.GetButtonDown("Fire1"))
{
Instantiate(Bullet,transform.position,Quaternion.identity);
Bullet.rigidbody.AddForce(transform.forward * 2000);
}
}
Here this should work, easy and simple. Make sure the bullet has a rigidbody attatched. :)
You can't (meaningfully) add force to a prefab, and you shouldn't usually instantiate something that isn't a prefab. You need to use (some other var : GameObject) = Instantiate( bullet, t.p, q.i ), then (some other var).rigidbody.etcetera. Also remember to keep variables in camelCase and functions in CamelCase.
Actually, no your code won't work. You need to AddForce to an instance of that Prefab, not the Prefab itself. You need var bullet : Rigidbody = Instantiate(); bullet.rigidbody.AddForce();
Answer by tool55 · Jan 30, 2011 at 01:44 AM
I wouldn't recommend instantiating bullets. A P90 is a machine gun, correct? Instantiating thousands of bullets is expensive from a performance standpoint, and you can't see them anyway if they're travelling so fast. There's another problem, which is that small game objects travelling very fast often "tunnel" through colliders. In other words, they pass through the collider undetected because the game only updates every frame, but the bullet has already passed through the collider in that time.
A more typical way to handle small arms fire is raycasting. Cast a ray from the gun and detect the hit using the RaycastHit class. You can still have the muzzle flash and sound, but the raycast does the work of telling you what game object has been hit, and you can score points or inflict damage that way.
I would save instantiation for things like cannonballs, rockets, etc.
Your answer
![](https://koobas.hobune.stream/wayback/20220613093300im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Shooting Pistol and Machine Gun 2 Answers
How can I shooting script c#? 0 Answers
DmC: Devil May Cry Dual Shot? 0 Answers
Help with fire script 1 Answer