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 Nercoe · Apr 11, 2013 at 09:13 PM · rotationconstraints

A better way than this to constrain angles?

Hey guys, I have made this script for my game. Basically it stops the bone from rotating too high and too low. It works which is a start but when I hit the angle specified, it jitters going back and forward. I know why it does this because I am saying if it is higher than this value, snap to that value. I am just wondering what I could do in order to make it stop when it hits the angle specified and not jitter, but when I want to move down, the bone moves again. Here is what I have so far:

 var spine : Transform;
 var rotateSpeed : int = 18;
 
 function Update()
 {
 
     if (gunAiming.aimMode == 1 || gunAiming.aimMode == 0)
     {
         spine.transform.Rotate(Vector3(0, 0, Input.GetAxis("Mouse Y")) * Time.deltaTime * rotateSpeed);
     }
     if (spine.transform.rotation.eulerAngles.z > 294)
     {
         Debug.Log("294");
         spine.transform.rotation.eulerAngles.z = 294;
     }
     
     if (spine.transform.rotation.eulerAngles.z < 244)
     {
         Debug.Log("244");
         spine.transform.rotation.eulerAngles.z = 244;
     }
 
 }
 
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
1
Best Answer

Answer by OP_toss · Apr 11, 2013 at 10:50 PM

Keep a running variable of the current rotation. Add to the variable instead of rotating transform Clamp the variable between your limits Apply the variable to your transform like so:

 transform.rotation = Quaternion.Euler( curRot )

Also, don't use Magic Numbers inside your code. Instead make vars at the top as constants in all caps. Mucho betterer.

Comment
Add comment · Show 3 · 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 DaveA · Apr 11, 2013 at 11:01 PM 0
Share

Please use Answer when answering a question

avatar image Nercoe · Apr 11, 2013 at 11:05 PM 0
Share

Thank you :)

avatar image OP_toss · Apr 12, 2013 at 02:02 AM 0
Share

No problem! Yeah new to this forum thing...

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

12 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

Related Questions

How does one constrain rotations of a CharacterController without a Rigidbody? 0 Answers

Rigidbody constraints not working with parent/child relationship 2 Answers

FPS Camera Control rotation limits 1 Answer

Freezing Rigidbody Rotation 1 Answer

Unfreeze Rigidbody ROTATION only 1 Answer


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