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 Steveosaurous · May 22, 2012 at 02:14 AM · instantiatetransformdirectionbulletgun

Bullets Based on Orientation

So I'm trying to set up a system where I have "GunNodes" which spawn bullets and fire them in the direction that the nodes are facing. So far, I've been having some trouble.

BulletCode:

   function Update () {
 LifeTime += Time.deltaTime;
 transform.position += Vector3.forward * BulletSpeed * Time.deltaTime;
 if(LifeTime >= Range){
     Destroy(gameObject);
 }

GunCode:

 function FireGuns (){
             FiringCoolDown = true;
             Instantiate(BulletObj, GunNode.position, GunNode.rotation);
             Handheld.Vibrate ();
             yield WaitForSeconds(FireRate);
             FiringCoolDown = false;
 }


Particularly, how can I spawn an object and cause it to move in the direction that another object is facing?

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
0

Answer by syclamoth · May 22, 2012 at 02:55 AM

In your bullet code, change this line:

 transform.position += Vector3.forward * BulletSpeed * Time.deltaTime;

to this:

 transform.Translate(Vector3.forward * BulletSpeed * Time.deltaTime, Space.Self);

Keep in mind that bullets that move in this way will not respond to colliders, or in fact any kind of collision detection. You will have to add a second step that sends a linecast between the bullet's position before and after the translation to manage collisions.

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 Steveosaurous · May 22, 2012 at 03:17 AM 0
Share

Wow that works fantastic!

Now, about the linecast. I'm developing this game for Android, any thoughts on how much impact a linecast will have on framerate if it's being called constantly?

avatar image syclamoth · May 22, 2012 at 03:27 AM 0
Share

Not significant. It's way more efficient than normal collision detection, anyway.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Rotation and Velocity of bullets. 1 Answer

Going crazy over simple bullets not instantiating in the correct position 0 Answers

Bullet not dissapearing after time ? 3 Answers

Problem with Shooting Accuracy 0 Answers

making bullet go travel at angle fired and limit gun rotation in Unity C# version 5.2 2D 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