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 /
This question was closed Dec 22, 2015 at 11:35 PM by Fattie.
avatar image
0
Question by SHG · Dec 22, 2015 at 08:38 PM · quaternionlerprotate objectmovetowardslerping

Quaternion.Lerp and Vector3.MoveTowards arent smoothing

The player can interact with a door and if it's raycasting towards the interactable object and the player left clicks/right trigger it either moves or rotates the object to or from the original position/rotation.

And it does do it, but not smooth even though I'm multiplying the Time.deltaTime part by a decimal (regardless of what I multiply it by it will instantly jump to that value).

Also as for the rotation part, it glitches out a lot (rotates immediately, but not even to the desired quaternion).

 private var m_isAxisInUse = false;
 var needtag : boolean = false;
 var Interactable : GameObject;
 var toggle : boolean = false;
 var on : boolean = false;
 var animating : boolean = false;
 var animName : String = "";
 private var animStarted : boolean = false;
 var moving : boolean = false;
 private var moved : boolean = false;
 private var originDest : Vector3;
 var moveDest : Vector3;
 var moveSpeed : float = 0.1;
 var rotating : boolean = false;
 private var rotated : boolean = false;
 private var originRot : Quaternion;
 var rotDest : Quaternion;
 var rotSpeed : float = 0.1;
 var style : GUIStyle = null;
 private var difference : int = 90;
 public var Message : String = "";
 public var Message2 : String = "";
 private var isViewing : boolean = false;
 var SoundEffect : AudioSource;
 var usingMultiClips : boolean = false;
 var Clip1 : AudioClip;
 var Clip2 : AudioClip;
 
 function Start(){
     originDest = Interactable.transform.position;
     originRot = Interactable.transform.rotation;
 }
 
 function Update () {
     var hit : RaycastHit;
     var fwd = transform.TransformDirection (Vector3.forward);
     
     if (Physics.Raycast (transform.position, fwd, hit, 1000)) {
         if(Vector3.Distance(Interactable.transform.position, transform.position) < 4){
             if(hit.transform == Interactable.transform && !needtag){
                 isViewing = true;
             }
             if(hit.transform.tag == Interactable.tag && needtag){
                 isViewing = true;
             }   
         }
     }  
     if(hit.transform.tag != Interactable.tag && needtag){
         isViewing = false;
     }
     if(hit.transform != Interactable.transform && !needtag){
         isViewing = false;
     }
     if(isViewing == true){
         if( Input.GetAxisRaw("Interact") != 1){
             if(m_isAxisInUse == false){
                 if(toggle){
                     on = !on;
                     if(on){
                         Interactable.SetActive(true);
                         SoundEffect.clip = Clip1;
                         SoundEffect.Play();
                     }
                     else if(!on){
                         Interactable.SetActive(false);
                         SoundEffect.clip = Clip2;
                         SoundEffect.Play();
                     }
                     if(!usingMultiClips){
                         SoundEffect.Play();
                     }
                 }
                 if(animating){
                     if(!animStarted){
                         GetComponent.<Animation>().Play(animName);
                         animStarted = true;
                         SoundEffect.Play();
                     }
                 }
                 if(moving){
                     moved = !moved;
                     if(!moved){
                         StartCoroutine("Move1");
                         Debug.Log("Should be moving");
                         if(usingMultiClips){
                             SoundEffect.clip = Clip1;
                             SoundEffect.Play();
                         }
                     }
                     else if(moved){
                         StartCoroutine("Move2");
                         Debug.Log("Should be moving");
                         if(usingMultiClips){
                             SoundEffect.clip = Clip2;
                             SoundEffect.Play();
                         }
                     }
                     if(!usingMultiClips){
                         SoundEffect.Play();
                     }
                 }
                 if(rotating){
                     rotated = !rotated;
                     if(!rotated){
                         //Interactable.transform.rotation = Quaternion.Lerp(originRot, rotDest, Time.deltaTime * rotSpeed);
                         if(usingMultiClips){
                             SoundEffect.clip = Clip1;
                             SoundEffect.Play();
                         }
                     }
                     else if(rotated){
                         //Interactable.transform.rotation = Quaternion.Lerp(rotDest, originRot, Time.deltaTime * rotSpeed);
                         if(usingMultiClips){
                             SoundEffect.clip = Clip2;
                             SoundEffect.Play();
                         }
                     }
                     if(!usingMultiClips){
                         SoundEffect.Play();
                     }
                 }
                 // Call your event function here.
                 m_isAxisInUse = true;
             }
         }
         if( Input.GetAxisRaw("Interact") == 1){
             m_isAxisInUse = false;
         } 
     }
 }
 
 function Move1(){
     var step = moveSpeed * Time.deltaTime;
     Interactable.transform.position = Vector3.MoveTowards(originDest, moveDest, step);
 }
 
 function Move2(){
     var step2 = moveSpeed * Time.deltaTime;
     Interactable.transform.position = Vector3.MoveTowards(moveDest, originDest, step2);
 }
 
 function OnGUI () {
         if(isViewing == true){
             if(!toggle && animating){
                 GUI.Label( Rect( (Screen.width/2)-difference, 10, 200, 25 ), Message, style);
             }
             else if(toggle){
                 if(!on){
                     GUI.Label( Rect( (Screen.width/2)-difference, 10, 200, 25 ), Message, style);
                 }
                 else if(on){
                     GUI.Label( Rect( (Screen.width/2)-difference, 10, 200, 25 ), Message2, style);
                 }
             }
             if(moving){
                 if(!moved){
                     GUI.Label( Rect( (Screen.width/2)-difference, 10, 200, 25 ), Message, style);
                 }
                 else if(moved){
                     GUI.Label( Rect( (Screen.width/2)-difference, 10, 200, 25 ), Message2, style);
                 }
             }
             if(rotating){
                 if(!rotated){
                     GUI.Label( Rect( (Screen.width/2)-difference, 10, 200, 25 ), Message, style);
                 }
                 else if(rotated){
                     GUI.Label( Rect( (Screen.width/2)-difference, 10, 200, 25 ), Message2, style);
                 }
             }
         }
         if(isViewing == false || animStarted == false){
             GUI.Label( Rect( (Screen.width/2)-difference, 10, 200, 25 ), "", style);
         }
 }

Please help me by pointing me in the direction of how I would be able to fix this. Thanks for reading, and happy holidays!

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

  • Sort: 
avatar image
1

Answer by Fattie · Dec 22, 2015 at 10:28 PM

Among other problems you don't seem to be setting originDest, in the code presented. Setting it "in Start" would not work.

In Update you should ONLY catch the trigger of the movement.

Then add a line of code

 Debug.Log("Door should rotate");

or similarly for the drawer.

Then write a SEPARATE ROUTINE to do the animation. You'd likely call that routine with a StartCoroutine

Once you do that and can show your output here, edit the question and someone will be sure to help.

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 SHG · Dec 22, 2015 at 11:24 PM 0
Share

Sorry about that, I just condensed the script so nobody would get confused with the extra functionality in it, but I found through debugging that the move coroutine is only called once when clicked on, but it still no matter what the value of movespeed is just teleports to that position ins$$anonymous$$d of lerping to it.

avatar image Fattie SHG · Dec 22, 2015 at 11:35 PM 0
Share

no need to be sorry but be sure to click edit and ... actually I tell you what. I will delete this question since it is old now. Please go ahead and post a new quetsion with your totally new code

Cheers!

Follow this Question

Answers Answers and Comments

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

Related Questions

[SOLVED] Rotation/angled offset in Quaternion.Lerp for a carried GameObject 2 Answers

Vector3.MoveTowards and Quaternion.RotateTowards 1 Answer

Quaternion.Lerp and Vector3.MoveTowards arent smoothing 1 Answer

Smooth camera 90 degree rotation around target 1 Answer

Changing rotation of Quaternion 0 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