- Home /
 
Unity, Y U IGNOR MY Y?
I have been trying to get my sidescroller shooter character to turn aside when the Y is higher than 90.
This is what I did:
 mousepos=Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x,Input.mousePosition.y,2));
 mousepos.x=0;
 
 if(hands.transform.rotation.y>90)
        {
        if(facefor)
          {
          facefor=false;
          me.transform.rotation=new Quaternion(0,0,0,0);
 
          }
        else if(!facefor)
            {
               facefor=true;
              me.transform.rotation=new Quaternion(0,-180,0,0);
 
            }
         }
        else
        {
          if(facefor)
           hands.LookAt(mousepos,Vector3.right);
          if(!facefor)
           hands.LookAt(mousepos,Vector3.left);    
        }
 
               But unity ignors the Y and keeps rolling with no switch! What could I do to make things right?
Perhaps you can debug it with print() functions inside and outside the conditions and see if it enters them. That's what it suggests me.
I'm not a quaternion expert, but I don't think you should be doing this: me.transform.rotation=new Quaternion(0,-180,0,0); Also if you're Y rotation is greater than 360, then it will repeat back at 0!
Answer by benk0913 · Jan 30, 2013 at 01:17 PM
I have used a vector2 and made it to switch directions when the mouse crosses the middle. :)
Answer by DaveA · Sep 14, 2012 at 07:00 AM
Use transform.eulerAngles.y instead
maybe Y axis is not what you need, try debuging all axies with a before applying rotation and after applying rotation and maybe there is something reseting the Y before the frame is rendered.
Your answer
 
             Follow this Question
Related Questions
Unity is ignoring the minus 4 Answers
Help with 2d platform shooter aim 0 Answers
Vertical auto-aim with raycasts 1 Answer
Firing a projectile from orbit 1 Answer
Third Person Aiming 0 Answers