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 parmeshwar · Feb 15, 2013 at 02:55 PM · gunfirespawnpoint

How to create spawnPoint for bullet shoot

hello and Hi I am developing an game which includes a gun, now i want to shoot bullet with gun i have made bullet prefab and applied fire script on gun but i don't know how to create spawnPoint. my gun is firing bullet if i m naming one of the game object as spawnPoint . but i want atleast a dot as i am aiming to object then i will fire to that dot point ...(spawnPoint)

using this simple fire code ...

 var BulletPrefab :Transform;
 var force : float = 2;
 
 function Update() 
 { 
     if(Input.GetButtonDown("Fire1")) 
     { var bullet = Instantiate(BulletPrefab,GameObject.Find("spawnPoint").transform.position,Quaternion.identity);
         bullet.rigidbody.AddForce(transform.forward * force);
 
 } } 
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
3

Answer by DMCH · Feb 15, 2013 at 03:19 PM

Hello ParmeshWar,

I think you are asking 2 questions here.

1) How to create a spawnpoint for your bullets

2) How to display an aiming reticule

1) To create a spawnpoint for bullets, create an empty gameobject, and position it just beyond the barrel of your gun. Make sure it is rotated in whichever direction you want your bullets to go. Now make it a child gameobject of your character/gun. (Do this by dragging the empty gameobject onto your character or gun)

Declare a field in whatever script you are instantiating the bullets in, and assign the empty gameobject to it in the inspector. Assuming you called the spawnPoint "bulletspawn" in your script, you could instantiate bullets from the spawnpoint like this:

 Instantiate(bullet, bulletSpawn.transform.position, bulletSpawn.transform.rotation);

Also, have a look at this tutorial, it's very close to what you need: http://www.youtube.com/watch?v=enLEpL0DrPM&list=PL11F87EB39F84E292∈dex=4

Hope this helps!

Comment
Add comment · Show 2 · 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 parmeshwar · Feb 18, 2013 at 05:32 AM 0
Share

thanks @DHC$$anonymous$$ now i am really interested in answer of the second question that you have noticed... i managed up till now besides aim point.... will u please give me any reference for ai$$anonymous$$g reticule

avatar image DMCH · Feb 28, 2013 at 05:57 PM 0
Share

Sorry, didn't see the reply. I'm not too sure about the reticule part. The only solution that comes to $$anonymous$$d is using OnGUI to draw a label at the centre of the screen. This should give you a start:

 private Texture2D reticule;

 void OnGUI()
 {
 Rect pos = new Rect(Screen.width/2 - reticule.width/2 , Screen.height/2 - reticule.height/2,reticule.width, reticule.height);
 GUI.Label(pos, reticule); 
 }

Hope this is of use. Consider accepting the answer if it has helped : )

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

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Reload clips on Gun-script not applied properly 1 Answer

Nullreference? 1 Answer

Is there a script out there that actully works for shooting bullets? 2 Answers

**[SOLVED]** Gun not firing after certain amount of shots 1 Answer

Game Object won't match rotation of new positions transform 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