- Home /
How to flip object according to its rotation?
So, I have a weapon that rotates towards my mouse position but the issue is if I put my mouse on the left side the weapon is upside down. So I've tried flipping it on the y axis according to its rotation but it constantly switches between both states (As in the y scale goes from - to + instead of sticking to one according to my mouse position.) Im not sure how to fix this. Any tips?
//Update Looking Direction
var rotationVector = transform.rotation.eulerAngles;
if (rotationVector.z < 90 && rotationVector.z > -90)
{
lookingLeft = false;
}
else if (rotationVector.z > 90 || rotationVector.z < -90)
{
lookingLeft = true;
}
if (lookingLeft == true)
{
transform.localScale = new Vector3(transform.localScale.x, transform.localScale.y * -1, transform.localScale.z);
}
if (lookingLeft == false)
{
transform.localScale = new Vector3(transform.localScale.x, transform.localScale.y * -1, transform.localScale.z);
}
Answer by DockAnkh · Jun 04 at 02:34 AM
It looks like lines 15 and 20 are doing the same thing. Since lookingLeft will always be true or false that command will be applied every time this code chunk is run.
Your answer
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
Changing the rotation of an object to match parent's rotation 1 Answer
how do I keep each cloned object at a certain point after trigger 0 Answers
How to make flat object(Unity 2D) 1 Answer
Slowly Change One Object's Rotation To Match Another's 2 Answers