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 BDX777 · Sep 02, 2014 at 12:09 AM · rotationquaternionbug-perhapsdoor

Quaternions incorrect?

Hi, I'm trying to program doors that open slightly when you scroll the mousewheel around, and my door gets rotated on its side?

 using UnityEngine;
 using System.Collections;
 
 public class BDXDoorScript : MonoBehaviour 
 {
     private float MaxRotation = 90f;
     private float MinRotation = -90f;
     private float RotateAmount = 20;
     public Quaternion DoorRotation;
 
 void Start ()
     {
         MinRotation = transform.rotation.z - 80f;
         MaxRotation = transform.rotation.z + 80f;
         DoorRotation = transform.rotation;
     }
 
 public void RotatePositive ()
     {
         print ("Doorscript_RotatePositive");
         DoorRotation = transform.rotation;
         DoorRotation.z+=RotateAmount;
         DoorRotation.z = Mathf.Clamp(DoorRotation.z, MinRotation, MaxRotation);
         transform.rotation = DoorRotation;
     }
 
 public void RotateNegative ()
     {
         print ("Doorscript_RotateNegative");
         DoorRotation = transform.rotation;
         DoorRotation.z-=RotateAmount;
         DoorRotation.z = Mathf.Clamp(DoorRotation.z, MinRotation, MaxRotation);
         transform.rotation = DoorRotation;
     }
 }

I'm trying to rotate the door, and clamp it by 90 degrees (Both set to 80 for debugging) both ways, so the door can only swing 180 degrees. Problem is, upon rotating... The door flips on its side? Is this something with .Blend fbx?

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 Eric5h5 · Sep 02, 2014 at 12:13 AM

You can't (or rather shouldn't) directly alter quaternion components. Quaternions are 4D structs that don't use degrees, so attempting to alter the z component does nothing useful. Use Transform.Rotate instead.

Comment
Add comment · Show 2 · 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 BDX777 · Sep 02, 2014 at 07:49 AM 0
Share

Oh thank you so much! It seems like when I program I have the right idea but I use the wrong method, one time I was trying to program something with material opacity and I thought it was 0 to 255 when it was actually 0.0 to 1.0!

avatar image BDX777 · Sep 02, 2014 at 12:02 PM 0
Share

Wait how would I go about clamping it in C#? You cannot directly access transform in C#, you would have to store it in a variable.

avatar image
1
Wiki

Answer by Mikeywalsh · Sep 02, 2014 at 12:42 PM

Change DoorRotation to be Vector3 and not Quaternion and this should work.

 public void RotateNegative ()
 {
    print ("Doorscript_RotateNegative");
    DoorRotation = transform.rotation.eulerAngles;
    DoorRotation.z -= RotateAmount;
    DoorRotation.z = Mathf.Clamp(DoorRotation.z, MinRotation, MaxRotation);
    transform.rotation = Quaternion.Euler(DoorRotation);
 }
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 BDX777 · Sep 03, 2014 at 02:03 AM 0
Share

This helps but does not fix clamping, so I moved DoorRotation = trasform.rotation.eulerAngles; to void Start() and it worked. Thanks for the help guys!

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

24 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

Related Questions

How to find a rotation of a child object 0 Answers

Quaternion rotation infinite? 1 Answer

Quaternion + many collision meshes = intense lag? 0 Answers

90 Degree stopping rotation on y-axis issue 0 Answers

Rotate object smoothly problem 3 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