Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Alex 4 · Jun 28, 2011 at 06:11 PM · rotationbugquaternion

Super strange rotation bug

Well,i have i script that places blocks and removes them. It has also an option to rotate desired cube.But when i try to rotate it 90 degrees it goes 179.xxxxxx .

Here is my script:

 var placeLayer : LayerMask = 1;
 var deleteLayer : LayerMask = 1;
 private var range : float = Mathf.Infinity;
 private var hit : RaycastHit;
 private var hitt : RaycastHit;
 var cubes : Transform[];
 private var selectedCube : int = 0;
 var playCloth : AudioClip[];
 var playGrass : AudioClip[];
 var playGravel : AudioClip[];
 var playSand : AudioClip[];
 var playSnow : AudioClip[];
 var playStone : AudioClip[];
 var playWood : AudioClip[];
 var currBlock : String = "";
 var positionCube : Rect;
 var positionCubeGUI : Rect;
 var textures : Texture2D[];
 var parentt : Transform;
 var placeBlockGUI : Texture2D;
 var rot : int = 0;
 
 function Update () {
     positionCubeGUI = Rect(0, (Screen.height-130), 210, 130);
     positionCube = Rect(12.5, (Screen.height-115), 100, 100);
     Screen.lockCursor = true;
     if (Input.GetMouseButtonDown(0))
         Build();
         
     if (Input.GetMouseButtonDown(1))
         Erase();
         
     if (Input.GetKeyDown(KeyCode.R)){
     if (HitBlock()) {
         
         hit.collider.transform.rotation.y += 1;
         
     }
     }
     
     SelectBlock();
     
 }
 
 function Build() {
     if (HitBlock()) {
         var cube = Instantiate(cubes[selectedCube],hit.transform.position + hit.normal,Quaternion.identity);
         currBlock = cube.name;
         playSoundToCubesName();
     }
 }
 
 function Erase() {
     if (HitBlockin())
     switch(hitt.transform.name){
     case "cubeStone(Clone)":
     playRandomBlockSound(5);
     break;
     
 case "cubeCobblestone(Clone)":
     playRandomBlockSound(5);
     break;
     
 case "cubeDirt(Clone)":
     playRandomBlockSound(1);
     break;
     
 case "cubeGrass(Clone)":
     playRandomBlockSound(1);
     break;
     
 case "cubeDiamond(Clone)":
     playRandomBlockSound(5);
     break;
     
 case "cubeGold(Clone)":
     playRandomBlockSound(5);
     break;
     
 case "cubeIron(Clone)":
     playRandomBlockSound(5);
     break;
     
 case "cubePlank(Clone)":
     playRandomBlockSound(6);
     break;
     
 case "cubeGlass(Clone)":
     playRandomBlockSound(5);
     break;
 /////////////////////////////////
 case "cubeWoolBlack(Clone)":
     playRandomBlockSound(0);
     break;
     
 case "cubeWoolBlue(Clone)":
     playRandomBlockSound(0);
     break;
     
 case "cubeWoolBrown(Clone)":
     playRandomBlockSound(0);
     break;
     
 case "cubeWoolDarkGreen(Clone)":
     playRandomBlockSound(0);
     break;
     
 case "cubeWoolDarkPink(Clone)":
     playRandomBlockSound(0);
     break;
     
 case "cubeWoolGreen(Clone)":
     playRandomBlockSound(0);
     break;
     
 case "cubeWoolLightBlue(Clone)":
     playRandomBlockSound(0);
     break;
     
 case "cubeWoolLightGrey(Clone)":
     playRandomBlockSound(0);
     break;
     
 case "cubeWoolOceanBlue(Clone)":
     playRandomBlockSound(0);
     break;
     
 case "cubeWoolOrange(Clone)":
     playRandomBlockSound(0);
     break;
     
 case "cubeWoolPink(Clone)":
     playRandomBlockSound(0);
     break;
     
 case "cubeWoolPurple(Clone)":
     playRandomBlockSound(0);
     break;
     
 case "cubeWoolRed(Clone)":
     playRandomBlockSound(0);
     break;
     
 case "cubeWoolYellow(Clone)":
     playRandomBlockSound(0);
     break;    
         
     }
         Destroy(hitt.transform.gameObject);
 }
 
 
 
 function SelectBlock(){
 if(Input.GetKeyUp(KeyCode.Keypad1)) selectedCube--;
 if(Input.GetKeyUp(KeyCode.Keypad2)) selectedCube++;
 if(selectedCube == cubes.length){
     selectedCube = 0;
 }
 if(selectedCube < 0){
     selectedCube = cubes.length-1;
 }
 
 }
 
 function playSoundToCubesName(){
 
 switch(currBlock){
 
 case "cubeStone(Clone)":
     playRandomBlockSound(5);
     break;
     
 case "cubeCobblestone(Clone)":
     playRandomBlockSound(5);
     break;
     
 case "cubeDirt(Clone)":
     playRandomBlockSound(1);
     break;
     
 case "cubeGrass(Clone)":
     playRandomBlockSound(1);
     break;
     
 case "cubeDiamond(Clone)":
     playRandomBlockSound(5);
     break;
     
 case "cubeGold(Clone)":
     playRandomBlockSound(5);
     break;
     
 case "cubeIron(Clone)":
     playRandomBlockSound(5);
     break;
     
 case "cubePlank(Clone)":
     playRandomBlockSound(6);
     break;
     
 case "cubeGlass(Clone)":
     playRandomBlockSound(5);
     break;
 /////////////////////////////////
 case "cubeWoolBlack(Clone)":
     playRandomBlockSound(0);
     break;
     
 case "cubeWoolBlue(Clone)":
     playRandomBlockSound(0);
     break;
     
 case "cubeWoolBrown(Clone)":
     playRandomBlockSound(0);
     break;
     
 case "cubeWoolDarkGreen(Clone)":
     playRandomBlockSound(0);
     break;
     
 case "cubeWoolDarkPink(Clone)":
     playRandomBlockSound(0);
     break;
     
 case "cubeWoolGreen(Clone)":
     playRandomBlockSound(0);
     break;
     
 case "cubeWoolLightBlue(Clone)":
     playRandomBlockSound(0);
     break;
     
 case "cubeWoolLightGrey(Clone)":
     playRandomBlockSound(0);
     break;
     
 case "cubeWoolOceanBlue(Clone)":
     playRandomBlockSound(0);
     break;
     
 case "cubeWoolOrange(Clone)":
     playRandomBlockSound(0);
     break;
     
 case "cubeWoolPink(Clone)":
     playRandomBlockSound(0);
     break;
     
 case "cubeWoolPurple(Clone)":
     playRandomBlockSound(0);
     break;
     
 case "cubeWoolRed(Clone)":
     playRandomBlockSound(0);
     break;
     
 case "cubeWoolYellow(Clone)":
     playRandomBlockSound(0);
     break;
     
 }    
 }
 
 function OnGUI()
 {
     GUI.DrawTexture(positionCubeGUI,placeBlockGUI);
     GUI.DrawTexture(positionCube, textures[selectedCube]);
 }
 
 function playRandomBlockSound(block : int){
 var wichOne : int = Random.Range(0, 3);
 
 if(block == 0) AudioSource.PlayClipAtPoint(playCloth[wichOne],transform.position);
 
 if(block == 1) AudioSource.PlayClipAtPoint(playGrass[wichOne],transform.position);
 
 if(block == 2) AudioSource.PlayClipAtPoint(playGravel[wichOne],transform.position);
 
 if(block == 3) AudioSource.PlayClipAtPoint(playSand[wichOne],transform.position);
 
 if(block == 4) AudioSource.PlayClipAtPoint(playSnow[wichOne],transform.position);
 
 if(block == 5) AudioSource.PlayClipAtPoint(playStone[wichOne],transform.position);
 
 if(block == 6) AudioSource.PlayClipAtPoint(playWood[wichOne],transform.position);
 
 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 function HitBlock() : boolean {
     return Physics.Raycast(transform.position, transform.forward, hit, range, placeLayer);
 }
 
 function HitBlockin() : boolean {
     return Physics.Raycast(transform.position, transform.forward, hitt, range, deleteLayer);
 }
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 aldonaletto · Jun 28, 2011 at 06:35 PM

You are modifying the rotation directly:

 hit.collider.transform.rotation.y += 1;

the rotation is a Quaternion - modifying its components directly will not give the results you expect. If you want to add some rotation around the Y axis (90 degrees, for instance), use Rotate:

 hit.transform.Rotate(0,90,0);

By the way, you don't need to write hit.collider.transform because RaycastHit informs the transform of the hit object too - just write hit.transform ; it maybe a little more efficient.

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 Alex 4 · Jun 28, 2011 at 06:39 PM 0
Share

thx dude !!! now it is working!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Unity Quaternion Problem (Should be A Bug?) 1 Answer

Problem with normal snapping and rotations. 1 Answer

2D character rotation wrong direction when moving 1 Answer

Quaternion - Rotate / Unrotate Error 0 Answers

i have rotated an gameobject but the axis of the object did not change 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