Hello 2D Toolkit community and Unikron Software, so basically, I want to rotate my characters arm towards the mouse. This hasn't anything to do with 2D Toolkit I guess.
I work with 2D platform controller from JNA Mobile, which is a third party asset bought from the Asset Store. This controller makes my character move and such, and I have made a Character Animation which changes the currently playing animation of the different body parts with for example: frontArm.Play ("walk_frontarm"), this all works well when nothing rotates towards the mouse position. this Animation Bridge also changes the scale of the parent gameObject so it will be mirrored.
The problem I'm facing is that when I move the mouse over the character (which is in the center of the screen), somewhere near the absolute center the arm rotates the wrong way! And stays that way until I change the scale of my character. Here is the rotation code:
private void AimDirection () {
if(inventoryAndEquipment.CurrentWeapon != null) {
Vector3 mousePos = Input.mousePosition;
mousePos.x -= Screen.width / 2;
mousePos.y -= Screen.height / 2;
float angle = Mathf.Atan2(mousePos.y, mousePos.x) * Mathf.Rad2Deg;
if (angle<0) angle += 360;
if (inventoryAndEquipment.CurrentWeapon is RangedWeapon) {
Quaternion rotation = Quaternion.Euler(0f, 0f, angle);
frontArm.transform.rotation = rotation;
}
}
}
I've tried different things which all end up to the same problem! All help and thoughts will be appreciated and the reason I ask it here is because I've already put a question in Answers from Unity3d, but only 1 person replied to me, which asked a question, so I couldn't find out the problem, this is the link to the Answers post:
http://answers.unity3d.com/questions/787125/negative-scale-and-rotation.htmlAll help will be appreciated. If you need more information to help me, like screenshots or more code, I see what I can do.
Screenshots will need to be discussed with a friend of mine because we're making the game together, and we both don't want to show anything unfinished, but if there is no other way, we'll provide you with screenshots.
Thanks in advance,
Kevin
So I've googled a for a bit more, and I found this post:
http://2dtoolkit.com/forum/index.php?topic=3370.0I think I have the same error because enabling and disabling the gameObject seems to work for me too..