Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Wesley S · Dec 30, 2010 at 04:06 PM · spawngunfire

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

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Justin Warner · Dec 30, 2010 at 05:39 PM 0
Share

http://www.youtube.com/watch?v=yE3zZPdQRas&feature=related

Is that what you mean?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

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. :)

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Loius · Dec 31, 2010 at 01:39 AM 0
Share

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.

avatar image Peter G · Jan 30, 2011 at 03:19 AM 0
Share

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();

avatar image Mathias · Jan 30, 2011 at 02:14 PM 0
Share

This works for me though.

avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

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

c# weapon shooting script using raycasting help 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges