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 MgBag · Mar 12, 2011 at 04:48 PM · rotationmaximumminimum

Maximum Rotation

Hey, here is a new one for you!

I want a maximum and minimum angle and I came up with this

function Update () {
    if (transform.eulerAngles.y > 10)
        transform.eulerAngles.y = 10;
    if (transform.eulerAngles.y < -10)
        transform.eulerAngles.y = -10;
}

But for some reason it's making my object rotate but kinda stutterly. This object is being moved by mouse with this script:

static var autoRotate : boolean; var rotateSpeed : float = 10; var MousePos : float; var XPos : float = 0;

function OnMouseDown () { autoRotate = true; }

function OnMouseUp () { autoRotate = false; }

function LateUpdate () {

MousePos = Input.GetAxis("Mouse X"); XPos = (-MousePos * rotateSpeed);

 if (autoRotate) 
     transform.Rotate(Vector3.up * XPos);

}

Now I my question; where do I, or Unity, go wrong?

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 SisterKy · Jul 15, 2011 at 01:17 AM 0
Share

Retagged $$anonymous$$ax to $$anonymous$$aximum to prevent confusion with 3dsmax. Retagged $$anonymous$$in to $$anonymous$$inimum... for symetry :p and because there were 2 '$$anonymous$$inimum'-Tags but only this one '$$anonymous$$in'-Tag. Greetz, $$anonymous$$y.

1 Reply

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

Answer by AngryOldMan · Mar 12, 2011 at 05:25 PM

this bit

function Update () {
    if (transform.eulerAngles.y > 10)
        transform.eulerAngles.y = 10;
    if (transform.eulerAngles.y < -10)
        transform.eulerAngles.y = -10;
}

should be like this

function Update ()
{
    if (transform.eulerAngles.y >= 10)
        transform.eulerAngles.y = 10;
    if (transform.eulerAngles.y <= -10)
        transform.eulerAngles.y = -10;
}

and change your floats to ints. As far as I know int will work with decimal placing and floats will not. Maybe just the way that I'm using them but it's working for us so worth a try.

Comment
Add comment · Show 4 · 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 MgBag · Mar 12, 2011 at 05:50 PM 0
Share

Thank you very much.

avatar image Peter G · Mar 12, 2011 at 10:00 PM 0
Share

floats store decimals and ints don't. And Euler Angles are stored as floats.

avatar image MgBag · Mar 13, 2011 at 01:44 PM 0
Share

Than how come I can get decimals in float?

avatar image AngryOldMan · Mar 13, 2011 at 09:02 PM 0
Share

like pete says u can get decimals in floats I think it's just how I've been using them.

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

1 Person is following this question.

avatar image

Related Questions

Bounds with Rotation: Getting y value of the point where its on the most left side of the collider (bounds.min.x) Note that the box collider has been rotated as well. 2 Answers

Flip over an object (smooth transition) 3 Answers

Restrict min/max rotation STILL wont work 1 Answer

Mouse look X axis not working? 0 Answers

How to set maximum and minimum rotation for an object 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