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 Itasko · Apr 14, 2015 at 11:18 AM · 2dtransform

Instantiated Prefab Facing Wrong Way

Heres a youtube video of my problem in action

I've been having a lot of trouble wrapping my brain around Quaternion rotations in Unity2D.

What I'm trying to do is so simple, yet it keeps beating me. I simply want to instantiate a prefab of fireball when I click the button. The problem is that I want the fireball to be facing in the direction of the mouse before firing along. I haven't gotten to the fire and velocity part because I can't get it face the right direction when it's created.

In my playercontrollerscript attached to the player Object I have this (In C#) if (Input.GetMouseButtonDown (0) && anim.GetBool ("canAtk")) { //Basic attack controls

         curTarget = Camera.main.ScreenToWorldPoint(Input.mousePosition);
 
         if(classState == "Cutter"){
             anim.SetTrigger ("attacking");
             anim.SetBool ("canAtk", false);
             StartCoroutine (AttackTiming ());
             anim.SetFloat ("animCombo", playerCombo);
         }
         else if(classState == "Flame"){
             Debug.Log (curTarget);
             var worldTarget = Input.mousePosition;
             Quaternion rot = Quaternion.LookRotation(transform.position - curTarget, Vector3.right);
             Rigidbody2D fballClone = (Rigidbody2D) Instantiate(fireBallz, transform.position, rot);


(You can safely ignore the cutter class part. The problem is when I'm in Flame class. I also have a script attached to the prefab object, but at this moment all it does is control Euler angles so it doesn't rotate along the weirdness axis.

Anyways, each time I hit the button it creates a fireball, but it's like they are 90 degrees behind where they should be. I say "like" because that's not always the case. If I click under my character, then the fireball is pointing up. If I click sort of "Down/right" it points "up/right".

This would be easier if I could visually wrap my head around how the rotations work. Any advice would be appreciated. If you need any more information or screenshots let me know as well. Thanks again.

Update: Now, if I click in the down/right or down/left or down it will create the fireball facing correct direction, but if it's "up" any, then it will pretty much face the opposite direction. Also, directly left or directly right causes the fireball to face down.

New Update: (Sort of just updating as I try to work it out.) I turned on Debug.Log(rot) just so I could see the rotation values when I create the fireball.

If I click bottom right I get (0.0, -0.6, -0.4, 0.7) the fireball is facing the correct position as it does always as long as I'm clicking in the "downish" area. When I click top right I get (-0.6, 0.0, 0.7, -0.3) and the fireball is facing Bottom-Left. So I click in the bottom-left direction and I get (0.6, 0.1, 0.7, -0.4) and it's facing bottom-left. My brain is so fried I'm not piecing it together correctly. Something I'm missing.

Comment
Add comment · Show 1
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 Bhargav5530 · Apr 14, 2015 at 11:27 AM 0
Share

Just change the scale of prefab to (-1,-1-,1) and try it. If you still not get the exact rotation of the ball then play with this value (1,-1), (-1,1). I hope my comment will help you.

0 Replies

· Add your reply
  • Sort: 

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

How can I make a collision sensitive teleporter for a 2D game #c 1 Answer

I am making a 2d game and I want to make it where to can pick up bricks with your mouse 3 Answers

Unity 5.1.1 Transform Lag/Bug 0 Answers

Is there a solution to when colliders bypass? 2 Answers

Inverting Position on One Axis 0 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