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 centaurianmudpig · Apr 13, 2012 at 05:09 PM · rotationeditorplaylimity-axis

Limit on x rotation axis in play mode

Hello, I am trying to rotate an object toward a target. I have achieved this on the Y rotation axis and trying to do the same for the X rotation axis. This is the code for rotating toward a target angle:

         diffAngle = Mathf.DeltaAngle(currentAngle, targetAngle);
     turnDirection = Mathf.Clamp(diffAngle / 20.0f, -1.0f, 1.0f);

It starts fine, rotating towards the target, but the rotation is clamped. Starting from 0 degrees, the object cannot rotate any further than 270 or 90 degrees. I tried adjusting the values in the editor, though I cannot drag the value beyond these limits. I tried adding a new Cube object, which does the same, so I have not coded anything to create this limit. When I stop the game the limitation is removed and I can rotate to any value I want.

I'm not sure why and would appreciate help in solving this problem.

Comment
Add comment · Show 2
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 dkNinja · Apr 13, 2012 at 06:10 PM 0
Share

I'm not sure if I understand this correctly, but are you asking why your script limits are not enforced when the game isn't playing. If so, scripts are generally not executed in the editor. To execute them in the editor, you have to add a flag [ExecuteInEdit$$anonymous$$ode] to the script. See http://unity3d.com/support/documentation/ScriptReference/ExecuteInEdit$$anonymous$$ode.html

avatar image centaurianmudpig · Apr 13, 2012 at 09:34 PM 0
Share

No pal. I have not set up any limits, but it limits the X rotation. I do not want any limits.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Owen-Reynolds · Apr 14, 2012 at 05:05 PM

That's a small code fragment. There's probably something messed up in the code that actually does the turning (which we can't see.) It looks like turnDirection is set up to go full-speed if past 20 degrees, then slow down within 20. Looks fine. You might make it a public so you can double-check it.

The Inspector is nothing. Whatever bug effectively limits rotation, naturally "snaps back" Inspector changes also.

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 centaurianmudpig · Apr 14, 2012 at 06:25 PM

Yeah that's right, about slowing down within 20. Here is a small [link text]unity project[1] reproducing the problem. It looks like DeltaAngle() returns a negative value after the initial 90 degree rotation, I don't understand, hopefully this example will say more.

[1]: http://answers.unity3d.com/storage/temp/633-RotateToTarget.zip

The rectangle (Hunter) should rotate to face the sphere (Prey).


RotateToTarget.zip (214.7 kB)
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

6 People are following this question.

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

Related Questions

Editor like position and rotation change of a game object 0 Answers

limit rotation to 90 degree on one axis 3 Answers

Editor windows disappear on play in Unity 5.5.2f1 1 Answer

Rotation limits 1 Answer

Limit Rotation of Rigidbody to 45 Degrees (Handlebars on a Bicycle) 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