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 Vuvuvi · Feb 04 at 03:57 PM · rotation2d gameaiminglimits

Adding a rotation limit to a pointing gun with cursor. I'm losing my mind.

Hi there. I'm working on a 2D platformer game with gun following the cursor for aiming. When the character is flipped, the rotation limit doesn't apply anymore. I'm losing it. See below the pictures. The limit is supposed to be the same of when he faces right. The same applies for the upper limit.

Here's the code

[CODE]

     if (_orientation.x < 0)
     {
         GameState._isCharacterFlipped = true;
         _parent.transform.localScale = new Vector3(-1, 1, 1);
         

         if (_shootFX != null)
         {
         _shootFXTransform.localEulerAngles = new Vector3(0, 180, 0);

         }

         if (_orientation.y < transform.localPosition.y)
              transform.eulerAngles = new Vector3(0, 0, (Mathf.Clamp(tempAngle, -180, 180 + _aimAngleRange/2)) - 180);
             //transform.eulerAngles = new Vector3(0, 0, (Mathf.Clamp(tempAngle, -180, 90)));
         else
         {
             transform.eulerAngles = new Vector3(0, 0, Mathf.Clamp(tempAngle, -180 - _aimAngleRange / 2, 180) - 180);
             //transform.eulerAngles = new Vector3(0, 0, Mathf.Clamp(tempAngle, 90, 180));

         }    


     }
          
     
        
     else 
     {

         GameState._isCharacterFlipped = false;

         if (_shootFX != null)
             _shootFXTransform.localEulerAngles = new Vector3(0, 0, 0);
         _parent.transform.localScale = new Vector3(1, 1, 1);
         transform.eulerAngles = new Vector3(0, 0, Mathf.Clamp(tempAngle, -_aimAngleRange / 2, _aimAngleRange / 2));
     }

[/CODE]

I've lost so many days on this I really don't know what to do anymore. Please help me.

Thanks

rotationdownflipped.png (125.9 kB)
rotationdownnotflipped.png (86.9 kB)
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by alexianphilosophy · Feb 04 at 05:34 PM

You can try and have two sets of clamping variables: one for when your character isn't flipped and one for when it is. I've worked with this type of rotation issue before, it's quite annoying. Another option is to flip the visuals of the player and manage the gun on its own.

Also, think of a 360 degree circle. It looks like you're trying to clamp the shooting from -180 degrees to 180 + some amount. 180 degrees and -180 degrees are the same thing. You're overshooting the 180 degrees, but it looks like would would have almost full range of motion in the first place. Maybe you're trying to clamp so the can can only face "forward"? That would look like a clamp from 90 to -90 degrees.

Try the two sets of variables for a start, probably. You can do that in tandem to making the sprite and the weapon flip individually as well to make it simpler. Also check out your range because it might just be that your range is a full circle and you don't realize it.

Hope this helped.

Comment
Add comment · Share
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

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

224 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Flip the player with arm rotation 2 Answers

Sprite will not roate when arrow keys are pressed 2 Answers

2D Sprite constantly flipping 0 Answers

How do I get a game object to follow camera rotation / transform.LookAt does not make my game object rotate 0 Answers

gimble lock and rotation problem 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