• 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 anant6 · 3 days ago · rotation

problem with rotation clamp

 tX = finger.ScreenDelta.x;
 tY = finger.ScreenDelta.y;
 primaryWeapon.transform.Rotate(new Vector3(-tY * primaryWeaponAgility * PlayerPrefs.GetFloat("ScopeSens") * Time.deltaTime, tX * primaryWeaponAgility * PlayerPrefs.GetFloat("ScopeSens") * Time.deltaTime, 0));
 primaryRotationX=Mathf.Clamp(primaryWeapon.transform.localEulerAngle.x, -6f, 6f); 
 primaryRotationY=Mathf.Clamp(primaryWeapon.transform.localEulerAngles.y, -36f, 36f);
 primaryWeapon.transform.localRotation=Quaternion.Euler(primaryRotationX, primaryRotationY, 0f);

I'm using this script to rotate my weapon object which a child of the player object the rotation happens every frame based on the touch input the script works fine except the part where its supposed to clamp the rotation of the weapon to stop it from facing the player. Now this part only works for the right and top rotation and not for bottom and left rotation Please suggest any possible solution to this problem as i'm unable to solve it by my self any suggestions and ideas would be really appreciated Thanks

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by aminbenslimen00 · 3 days ago

i 've an idea of clamping the rotation respecting the player(parent)'s transform.forward . what i mean by that is to keep track of( primaryWeapon.transform.forward - parent.transform.forward) and if it exceed threshold or -threshold u just stop it from rotation

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
avatar image
0

Answer by anant6 · 3 days ago

@aminbenslimen00 That isnt working as well because the rotation is not going to +36 and -36 it going from 360 to 320 on the left side

Comment
Add comment · Show 1 · 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
avatar image anant6 · yesterday 0
Share

please anyone?? help??

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

153 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

Related Questions

Flip over an object (smooth transition) 3 Answers

making an object below this object follow rotation on y axis 0 Answers

Limit transform.LookAt to 90 degrees based off of object's forward axis 1 Answer

Child ignoring parent rotation? 1 Answer

[Model] Imported Model - Resets to random rotation upon Play Mode 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges