- Home /
2D sprites, Negative scaling flips my look at mouse
Hello,
I have been working on a 2D side scroller using the new 2D system introduced with the newer version of unity.
I was following the Brackeys brief unfinished tutorial on it and he downloaded and imported the 2D folder of the Sample Assets (Beta) package released from unity. Link here
We are using the character movement script that came with it and in it, it checks if you are going left or right and it scales the character along the X negatively if you're going left.
void Flip ()
{
// Switch the way the player is labelled as facing.
facingRight = !facingRight;
// Multiply the player's x local scale by -1.
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
In the tutorial Brackeys has a mouse script that he puts on the arm which is a child of the main character sprite:
public class ArmRotate : MonoBehaviour
{
public int rotationOffset = 90;
//public float maxZ = 40f;
//public float minZ = 335f;
// Use this for initialization
// Update is called once per frame
void Update ()
{
Vector3 difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
difference.Normalize();
float rotZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(0f, 0f, rotZ + rotationOffset);
}
}
The arm rotates perfectly when looking right, but the issue happens when we look left and he scales to -1. The arm, instead of looking at the mouse position he looks at the correct position, but because of his negative scale its opposite on the X and I have no idea how to fix it...
If anyone could shed some insight on how to fix this I would be more than grateful.
Thank you.
Idk if this helps, but have you tried setting "rotationOffset" to 0 in the inspector? i think he mentions this in his video aswell
Oh yeah, without it being at 0 it doesn't face the mouse (when facing right) but that variable has no effect when facing left :/
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
How to keep my cursor inside window boundaries 0 Answers
How to make 2d distortion? 2 Answers
If i click on a object i move to the next level (c#) 0 Answers
Apply force towards mouse click 2D C# 0 Answers