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 Major Fool · Jul 25, 2014 at 05:44 AM · c#rotationgameobjectinstantiateprefab

Thrown objects always have same rotation

I am trying to have the player throw a fireball prefab every time the left-mouse button is clicked. The fireball spawns and is thrown away from the player, however, it always goes the same direction. The rotation I give the fireball is that of the camera's X and the player's Y. I can't seem to figure out why it is not using the correct rotation.

         if(Input.GetButtonDown("Fire1")){
 
             GameObject temp = (GameObject)GameObject.Instantiate(fireBall, 
                  new Vector3(player.transform.position.x,
                          player.transform.position.y,
                         player.transform.position.z),
                     Quaternion.Euler(camera.transform.eulerAngles.x,
                         player.transform.eulerAngles.y,
                         0));
 
             Debug.Log(camera.transform.rotation.eulerAngles.x);
             Debug.Log(player.transform.rotation.eulerAngles.y);
 
             temp.rigidbody.AddForce(force, force, 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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · Jul 25, 2014 at 05:46 AM

You don't give us enough enough information/code to nail everything down, but assuming your fireball is facing the correct direction (i.e. your Quaternion.Euler() is giving you what you want), the last line is wrong. Here is an alternate:

 temp.rigidbody.AddForce(temp.transform.forward * force);
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 Major Fool · Jul 25, 2014 at 09:47 AM 0
Share

Thank you! This fixed my problem.

avatar image
0

Answer by akashsunny · Jul 25, 2014 at 08:40 AM

the cause is That you are using the camera's euler angles .. By closely observing your game you can find out that the camera's angles are constant that is the problem which is causing the issue. try using the player's angles

if you found this helpful or if there is anything more that you would like to know pls post again.

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 Major Fool · Jul 25, 2014 at 09:48 AM 0
Share

Thank you for trying to help, but it's fixed now.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Rotate an Instantiated GameObject a set amount from another instantiated GameObject? 1 Answer

Save gameobjects prefabs from scene A to a list, then instantiate those game objects to another scene. 0 Answers

How to create GameObject without adding it to scene? 1 Answer

2D Projectile Not Firing Based on Rotation 1 Answer

How to make a gameObject instantiate a prefab for every 250 damage taken ? 4 Answers


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