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 Gooey-Man · Oct 29, 2013 at 03:45 PM · bulletjava

My bullet follows my plane...

I have a plane that shoots a bullet in 2d. One is called plane and the other called bullet! That simple! When I hit the space bar the bullet fires. If I hit the space bar and then move the plane the bullet playing its "bullet fire" animation the whole animation with the bullet moves:( I want the bullet to fire stay in one spot when the plane moves and hit something. But plane moves bullet moves... How can I fix this? Here are my codes...

This is the bullet's code...

 function Update()
 {
 if(Input.GetButton("Jump"))
     {
     animation.Play("Bullet Fire");
     }
 }

Now here is the code for the plane...

 function Update() 
 {
     if(Input.GetButton("Fire2"))
     { 
          //do something
          transform.position.x += 0.3;
     }
     else if(Input.GetButton("Fire1"))
     {
          transform.position.x -= 0.3;
     }
     
 }
 
 
 function OnCollisionEnter (col : Collision)
 {
     if(col.gameObject.name == "enemy")
     {
         Destroy(gameObject);
         Destroy(col.gameObject);
     }
 }

Thanks for helping!

Comment
Add comment · Show 2
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 Gooey-Man · Oct 29, 2013 at 07:25 PM 0
Share

How do I instantiate bullets?

avatar image Gooey-Man · Oct 29, 2013 at 07:26 PM 0
Share

Or get an object pool?

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Kiloblargh · Oct 29, 2013 at 04:02 PM

The answer should be obvious. You have the bullet animation attached to the plane and you are animating the bullet relative to the plane. You can't do that. You need to instantiate bullets. ( Actually instantiating bullets is never good practice, so you need an object pool but get a clue first and then worry about performance optimization. )

Comment
Add comment · Show 1 · 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 Gooey-Man · Oct 29, 2013 at 07:27 PM 0
Share

How do I instantiate or get a object pool?

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

15 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 avatar image avatar image avatar image avatar image

Related Questions

My bullet wont move forward 1 Answer

Gun Script Error (Fixed!!!) 1 Answer

Accessing Coroutine from another Script? 1 Answer

Main menu camera change script. 1 Answer

Convert js joystick script to c# but not working 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