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 benk0913 · Sep 08, 2012 at 02:09 PM · rotationshootersidescrollertransform.lookat

Unity is ignoring the minus

I have been trying to get my sidescroller shooter character to turn aside when the rotations z is lower than -0.4 and turn to the other side when its higer than -0.4 so the character wont shoot one direction while facing the legs to the other. ( Simply shooting from between its legs (XD).) Most of the times the character turns when it reaches -0.4 but in some cases (randomly yet) it just ignors the minus (while the z shows it should turn and gets the charactars head between the legs.

Here is the piece of code wich gets it to turn:

 mousepos=Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x,Input.mousePosition.y,2));
         mousepos.x=0;
         if(hands.transform.rotation.z<-0.4)
         {
             facefor=false;
             me.transform.rotation=new Quaternion(0,0,0,0);
             hands.LookAt(mousepos,Vector3.right);
         }
         if(hands.transform.rotation.z>-0.4)
         {
             facefor=true;
             me.transform.rotation=new Quaternion(0,-180,0,0);
             hands.LookAt(mousepos,Vector3.left);
         }
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

4 Replies

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

Answer by benk0913 · Sep 10, 2012 at 08:26 AM

I have used a vector2 and made it to switch directions when the mouse crosses the middle. :)

Comment
Add comment · 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
1

Answer by Owen-Reynolds · Sep 08, 2012 at 03:14 PM

The whole things looks odd to me -- shouldn't you be comparing the way you face now to the way the mouse wants to shoot? But...

Both ifs are triggering. The 1st spins you to face right, then the second checks the changed value of hands, sees you are now facing right, and spins you back left. Replace the 2nd if(....) with a single else to guarantee only one of those happens.

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 Fattie · Sep 08, 2012 at 03:22 PM 0
Share

is there a cool program$$anonymous$$g term of art (along the lines of, say, "unity error" or "infinite loop" or the like) when you fogget that you have already changed a value in an algorithm ?!!

avatar image
0

Answer by benk0913 · Sep 09, 2012 at 03:32 PM

Didn't work, stumped.,Didnt work, still stumped.

Comment
Add comment · 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
0

Answer by kristercollin · Sep 09, 2012 at 05:00 PM

I'm under the impression that Owen is right about this. Firstly, could you place

 Debug.Log("less than -0.4, turning.");

and a

 Debug.Log("greater than -0.4, turning.";

where appropriate, then test the game and see what the output gives you using the step-by-step feature? It seems to me that both will call during update.

If that is the case, then, as Owen suggested, you should change your code to be like this:

 if(hands.transform.rotation.z<-0.4)
        {
          facefor=false;
          me.transform.rotation=new Quaternion(0,0,0,0);
          hands.LookAt(mousepos,Vector3.right);
        }
 else
        {
          facefor=true;
          me.transform.rotation=new Quaternion(0,-180,0,0);
          hands.LookAt(mousepos,Vector3.left);
        }
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 benk0913 · Sep 10, 2012 at 08:20 AM 0
Share

Tried so, didnt work. I tested it before I asked the question ):

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

10 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

Related Questions

Unity, Y U IGNOR MY Y? 2 Answers

How Can i Make Fps Controller Rotate and face a target. 0 Answers

Best way to place a name tag over a player? 1 Answer

simple movement and rotate help! 1 Answer

How do I rotate a character with joystick input in an isometric view? 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