Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by kraaijmakers · Sep 08, 2014 at 01:32 PM · rotationscalingnegative

Negative scale, rotation and center of screen deathspot

Hello,

I have a problem with rotation and scaling. I rotate my characters arms with the following code:

     Vector3 mouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
     Vector3 toMousePos = mouseWorldPos - transform.position;
     toMousePos.z = 0;
     frontArm.transform.up = -toMousePos;
     backArm.transform.up = -toMousePos;

All works well until my character moves, then the arms are being the wrong direction. The game is a 2D platformer with shooting elements. the Arms should rotate towards the mouse. I use 2D Platform Controller for the movement, and 2D Toolkit for the 2D related tasks. My characters arms stay on the same position because of a script that sets the position of the transform to a attachPoint in the body, which is a snippet by 2D Toolkit, which I altered to not include the rotation.

I also tried setting the Mouse Position to angles and update the Z rotation of arms, which has the same effect. I hope somebody can help me, I will look further into this problem myself too and post information and maybe even a solution as soon as I found one. For more information, just reply to this thread.

Thanks in advance,

K93

Edit: Basically it works better now, I use the following 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.localRotation = rotation;
             }
         }    
     }

Which works way better, but the problem now is that when the character quickly changes scale by moving the mouse over the character to the left, the rotation is not aligned properly. Sometimes it's the opposite, sometimes it's just a bit. I've searched a lot of questions on here already, this is how I came up with the following solution. But somehow the center of the screen has some kind of death spot. Which changes the rotation to an undesired state.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Mayank Ghanshala · Sep 08, 2014 at 02:13 PM 0
Share

Are you using Split animation

avatar image kraaijmakers · Sep 08, 2014 at 02:31 PM 0
Share

No, not that I know of, what do you mean by that?

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

how to prevent scaling the viewport when rotating the phone ? 1 Answer

Bug in rotation when going to opposite quadrant 1 Answer

Set GUI within 4 points - Matrix Rotation/Distortion 0 Answers

Negative Scaling or Separate Models 0 Answers

Rotation on the negative X axis won't be checked.. 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges