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 hanaharu7 · Jan 17, 2014 at 09:53 AM · rotationjavascriptdirectioncontrols

Rotate the same way no matter what direction facing?

Hello!

Im having some trouble trying to get the halls to rotate properly. I'm trying to set up the controls in such a way that when you right click any wall, it rotates the level down 90 degrees and left clicks rotate the level up 90 degrees(using the FPC as the pivot point); no matter which direction the walls are facing. Right now it only works correctly on some of the walls (it's reversed on the opposite wall)and I'm not sure why.

 var Player : Transform;
 var rotateAmount = 90;
 var controller : CharacterController;
 var Hit : RaycastHit;
 
 private var isRotating = false;
 
 function FixedUpdate () {    
     //casts a ray from camera to point in world
    var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
     // If the controller is grounded and the ray hits an object; then you can Rotate walls
     if (controller.isGrounded && Physics.Raycast(ray, Hit, 50)&&(isRotating==false)) {
     
         var Hitobject : GameObject = Hit.transform.gameObject;
         var pivot : Transform = Hitobject.transform;
         Debug.DrawLine(transform.position, Hit.point);
             canRotate = true;  
     
             if((Input.GetMouseButtonDown(0))&&(Hitobject.gameObject.tag=="Wall")){
                 RotateObjectF(Player.position,pivot.right, 90,1);                            
                 }     
             if((Input.GetMouseButtonDown(1))&&(Hitobject.gameObject.tag=="Wall")){
                 RotateObjectF(Player.position,-pivot.right,90,1);                            
                 }     
 }
 }
 function RotateObjectF(point : Vector3, axis : Vector3, rotateAmount : float, rotateTime : float) {
     var step : float = 0.0; //non-smoothed
     var rate : float = 1.0/rotateTime; //amount to increase non-smooth step by
     var smoothStep : float = 0.0; //smooth step this time
     var lastStep : float = 0.0; //smooth step last time
 
     while(step < 1.0) { // until we're done
         isRotating = true;
         Debug.Log("Rotating");
         step += Time.deltaTime * rate; //increase the step
         smoothStep = Mathf.SmoothStep(0.0, 1.0, step); //get the smooth step
         transform.RotateAround(point, axis, 
                                rotateAmount * (smoothStep - lastStep));
         lastStep = smoothStep; //store the smooth step
         yield;
     }
     isRotating = false;
     if (isRotating == false){    
     Debug.Log("not Rotating");
     }
     //finish any left-over
     if(step > 1.0) transform.RotateAround(point, axis,
                                           rotateAmount * (1.0 - lastStep));
 }


alt text

The left side is how the script works now and the right is what I'm trying to achieve.

Any help would be greatly appreciated :)

pushg.jpg (188.1 kB)
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 HappyMoo · Jan 17, 2014 at 10:48 AM 0
Share

haven't looked at code yet. What is rotating a level up/down 90 deg exactly? Through the FPC pivot i get, but around which axis? Do you mean right click should make the clicked wall a floor and left click a ceiling?

avatar image hanaharu7 · Jan 17, 2014 at 05:40 PM 0
Share

All the walls and floors together and at the moment, I believe it to be the yaxis. Also correct, right click should make the clicked wall a floor and left click a ceiling

1 Reply

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

Answer by HappyMoo · Jan 18, 2014 at 02:09 AM

Vector3 axis = Vector3.Cross( Hit.normal, Vector3.up);

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 hanaharu7 · Jan 18, 2014 at 09:02 AM 0
Share

Thank you soo $$anonymous$$uch!!! it worked peferctly!

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

19 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

Related Questions

How to rotate instantated prefab without rotating it's local directions by javascript? 1 Answer

[JS] transform.rotation not working 1 Answer

rotation LookAt of 2D gameObject in 3D space 1 Answer

Slerp Problem?: Enemy in Constant Rotation! 1 Answer

Camera/Direction Rotation 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