Hello Guest

Author Topic: Spot of input.mousePosition and Rotation of sprite  (Read 5447 times)

Kevin

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 9
    • View Profile
Spot of input.mousePosition and Rotation of sprite
« on: September 10, 2014, 05:10:56 pm »
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:
Code: [Select]
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.html

All 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.0
I think I have the same error because enabling and disabling the gameObject seems to work for me too..
« Last Edit: September 10, 2014, 10:17:14 pm by Kevin »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Spot of input.mousePosition and Rotation of sprite
« Reply #1 on: September 13, 2014, 12:21:47 pm »
I don't get this, if the character is flipped the rotations will naturally be flipped too... Dont get why disabling and enabling will change anything. Can you post an example scene / repro case for this?

Kevin

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Spot of input.mousePosition and Rotation of sprite
« Reply #2 on: September 18, 2014, 03:19:50 pm »
Sorry for the late reply. Is it okay I send you the full source via Google Drive or something?
And if so, can you send me a private message with your details.

Thanks in advance,
Kevin

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Spot of input.mousePosition and Rotation of sprite
« Reply #3 on: September 19, 2014, 02:59:44 pm »
You can email support at unikronsoftware dot com.
Yup, a google drive link is fine.

Kevin

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Spot of input.mousePosition and Rotation of sprite
« Reply #4 on: September 29, 2014, 07:33:31 pm »
Hello Unikron Software,

Have you had the time to look into it? And if so, has any progress been made?
Thanks in advance,
Kevin

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Spot of input.mousePosition and Rotation of sprite
« Reply #5 on: September 30, 2014, 10:50:13 am »
I don't think I got this? Could you resend please.

Kevin

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Spot of input.mousePosition and Rotation of sprite
« Reply #6 on: September 30, 2014, 03:53:32 pm »
I resend the mail to support at unikronsoftware dot com
Let me know if you still have problems viewing or getting the e-mail address.

Thanks in advance,
Kevin