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
2
Question by Taavi Uotila · Oct 30, 2010 at 01:46 PM · 2drotationjavascriptx-axismaximum

How to set maximum and minimum rotation for an object

Hi! I'm trying to make a 2d cannon game, but I've faced a problem. I should limit the x-rotation of that object between 10 and 80. Thank You!

Comment
Add comment · Show 1
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 Jesse Anders · Oct 30, 2010 at 02:14 PM 0
Share

Does the object only rotate on the x axis?

2 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by duck · Oct 30, 2010 at 02:48 PM

This would depend on how you're rotating the object in the first place. If you're using physics and torque, a configurable joint would fit well.

If you're rotating by manipulating the transform directly, without physics, it's probably best to maintain a variable containing the angle, and limit it yourself, perhaps using the Mathf.Clamp function. For example:

var angle = 45.0;

function Update() {

 angle += Input.GetAxis("Vertical") * Time.deltaTime * 10;
 angle = Mathf.Clamp( angle, 10, 80 );

 transform.localRotation = Quaternion.AngleAxis(angle, Vector3.right);

}

If you need a more detailed answer, please edit your question to include more detail about how you're rotating the object.

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 Eric5h5 · Oct 30, 2010 at 03:56 PM 0
Share

transform.rotation is a quaternion...but you know that. :)

avatar image duck ♦♦ · Oct 30, 2010 at 06:40 PM 0
Share

oops, of course! bad example - fixing now

avatar image duck ♦♦ · Oct 30, 2010 at 06:48 PM 0
Share

fixed. for all relevant disclaimers, please see my profile page ;-)

avatar image
0

Answer by Eric5h5 · Oct 30, 2010 at 03:59 PM

Have a look at the MouseLook script in Standard Assets, which has a rotation clamp function that would work perfectly in this situation as long as you're directly setting the rotation and not using physics. If you need a Javascript version of MouseLook.cs, it's here.

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

No one has followed this question yet.

Related Questions

Disabling the Z axis? 1 Answer

2d Enemy JavaScript 0 Answers

2D: Rotating to face mouse position with two fixed axes 1 Answer

Making the players head face toward the location of the mouse? 1 Answer

rotation LookAt of 2D gameObject in 3D space 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