Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Jaimieself · Mar 08, 2018 at 08:51 PM · instantiateprefab

Arrows fire in reverse.

I have a simple bow system where when the left mouse button is released the arrow prefab instantiates and then fires towards a ray-cast hit point, up to this point it is working well.

The problem is that the arrow prefab always instantiates pointing in the wrong direction (180 degrees out)

I have tried rotating the prefab in unity by 180 degrees. I have gone into 3DS max and rotated to the model 180 degrees. I have played about with the code by putting " * -1" in various places (unity didn't like this one bit).

So i'm ready to throw this out to someone else now as even my university lecturer cant figure it out.

Here is the update function:

void Update ()

 {

     if (currentAmmo > 0) {

         if (Input.GetButtonUp ("Fire1")) 
     
     {

             Rigidbody instance = Instantiate (arrow, transform.position,
                                      transform.rotation) as Rigidbody; 

             Vector3 fwd = transform.TransformDirection (Vector3.forward);
             instance.AddForce (fwd * power);

             currentAmmo--;

         Debug.Log (currentAmmo);

     }
             
 }

}

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 meat5000 · Mar 08, 2018 at 09:01 PM

In the code you can use AddRelativeForce instead of Addforce and then you can just add to the z axis. That'll simplify the whole TransformDirection.

As far as the rotation goes, did you create a fresh prefab after Importing the updated Arrows? Did you Save Project after creating or modifying prefabs? If you have tried these things then you should consider creating spawning a parent object and making a child of the arrow, then you can easily have it any way round you like. Perhaps mark the head and the tail with empty objects and save the prefab. You can use the orientation of the objects you created to orient the arrow as a hack.

Comment
Add comment · Show 10 · 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 Jaimieself · Mar 08, 2018 at 09:44 PM 0
Share

Yeah i deleted the old prefab and re imported the new model. Ill go though it again tomorrow just to make sure i did it right.

avatar image meat5000 ♦ Jaimieself · Mar 08, 2018 at 10:01 PM 0
Share

Remember that Saving Project after messing with prefabs is essential.

avatar image Jaimieself meat5000 ♦ · Mar 09, 2018 at 04:49 PM 0
Share

O$$anonymous$$ i have tried a new prefab just to make sure and I tried rotating the parent object. I'm going to try the last part you suggested.

Show more comments

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

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

Related Questions

Spawn in a different and random Spawn point from a list 0 Answers

Instantiate prefab with its component c# 0 Answers

Create gameobject in other scene... 0 Answers

Trying to get a 2d prefab without rigidbody to instantiate on button press, "the variable T_Bullet has not been assigned." 0 Answers

Want to instantiate Prefab in its parent. 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