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 -GenericPath- · Sep 30, 2014 at 11:38 AM · rotationrigidbodyquaterniongravityslerp

Rotating Rigidbodies

Hi, I'm currently creating a gravity switching puzzle game (or atleast starting to create) and I have gotten to the point where I have my player able to change gravity but I want to be able walk around on the surface the gravity changed to. All I need to do is just rotate to a specific quarternion/quarternion.euler but after multiple days looking around and testing I have reached no where. I attempted various methods and so far have ended up with this

             function Update ()
             {
                    if (Input.GetMouseButton(0))
                    {
                         var hit : RaycastHit;
                         var ray : Ray = playerCamera.camera.ViewportPointToRay (Vector3(0.5,0.5,0));
                         if (Physics.Raycast (ray,hit))
                               {    
                                     var incomingVec = hit.point - transform.position;
                                 var refectVec = Vector3.Reflect(incomingVec, hit.normal);
                                 hitPoint = hit.point;
                                 hitNormal = hit.normal;
                                 targetPos = hit.transform.rotation;
                                         
                                 GravityNormal (hitNormal);
                                 GravityRotate ();
                               }
             
                       }
         }
                     
                     function GravityRotate ()
                     {
                         var orginRot = transform.rotation;
                         var targRot = targetPos;
                         rigidbody.isKinematic = true;
                         
                         for (var t: float = 0.0; t < 1.0; ){
                             t += Time.deltaTime;
                             transform.rotation = Quaternion.Slerp(orginRot, targRot, t);
                             yield; // return here next frame
                         }
                         
                         rigidbody.isKinematic = false;
                     }
             
         

There is a few things in there from other parts of the script (it also has all of my movement and gravity stuff) but this is copy pasted everything to do with my rotating part minus a few debug.log's and comments. It does rotate however once its finished rotating it goes straight back to its original point. As a note I'm using the unity 4.6 beta 17

Comment
Add comment · Show 7
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 HarshadK · Sep 30, 2014 at 11:47 AM 1
Share

What is dstRot? After rotating your object using for loop you are setting your transform's rotation to be this dstRot which might be the issue.

avatar image khenkel · Sep 30, 2014 at 11:58 AM 0
Share

Also, does the "yield" statement even work? I'm not into JavaScript that much but shouldn't you be using "StartCoroutine(GravityRotate())" ?

avatar image Bunny83 · Sep 30, 2014 at 12:24 PM 1
Share

@khenkel: No, that's the correct syntax in UnityScript. In UnityScript Unity automatically uses StartCoroutine when it's an IEnumerator. Also the C# "yield return null;" is just "yield;" in US.

avatar image khenkel · Sep 30, 2014 at 12:26 PM 0
Share

Ah thank you very much, I didn't know that!

avatar image -GenericPath- · Sep 30, 2014 at 11:22 PM 0
Share

dstRot is the target rotation, I put that there as an attempt to maybe get it to set to that instantly after but that didn't work either. I removed it so others can avoid that confusion (even if it is defined within the script >_<)

Show more comments

2 Replies

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

Answer by -GenericPath- · Oct 01, 2014 at 01:48 AM

Well the issue was completely opposite to what I thought it was. Firstly I found about Quaternion.LookRotation. And that seems more fitting/easier to use, Secondly I realized the overlying issue was my mousescript was interfering with the rotating. All i do now is just disable the mouse script while it is rotating which was causing the issues with any and all types of rotation. I had it so my player would rotate but the mouselook script was acting strangely so i disabled it and rotation worked perfectly. Here is a simple piece of code for anyone else with the same issue.

 mouseScript.enabled = false;
 transform.rotation = Quaternion.RotateTowards(transform.rotation, targetTransform.rotation, turnSpeed * Time.deltaTime);




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 KEELAN · Sep 30, 2014 at 11:54 AM

You are setting the rotation to dstRot after the loop. This is probably (depending on what dstRot is) causing your problems, the fact that it rotates then gets set back. Just remove that line and it should work.

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 -GenericPath- · Sep 30, 2014 at 11:26 PM 0
Share

That line was added there in an attempt to fix the problem, I was thinking that since it rotated to dstRot in the slerp but instantly went back to original position i could just add that and it would fixed it in a roundabout way. But even that didn't fix it. Removing it doesn't change anything. I removed it so others can avoid that confusion (even if it is defined within the script >_<)

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

29 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

make projectiles always hit target 1 Answer

Use Lerp to rotate object 2 Answers

Rotation approximation issues using Quaternion.LookRotation 0 Answers

Basic AI Locked Axis 1 Answer

Player character X rotation going haywire on game start 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