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 NewEonOrchestra · Oct 25, 2012 at 05:31 AM · lagdooropen

Door script lag with rotation (Quaternion.slerp ?)

I'm having some trouble using this slightly modified door script (javascript) I found off of Youtube. It works fine, but the problem is that I get a huge amount of lag from it. I've isolated which lines are causing the lag, and it is the Quaternion.slerp operations, and I have no idea why.

I have experience with coding but not with javascript in particular, nor am I familiar with the transform options. Can anyone point out why this script lags? I imagine because it is grabbing information every update when it doesn't necessarily need to, and that I could write a "sleep" function that skips any transform operations after the door has completed opening or closing, but that still means I'll get a bit of heavy lag for the few seconds while the door is swinging.

Any thoughts?

Thank you very much!

 // Smothly open a door
 var smooth = 2.0;
 var DoorOpenAngle = 90.0;
 var DoorCloseAngle = 0.0;
 var open : boolean;
 var enter : boolean;
 
 var myTransform;
 
 function Awake() {
     myTransform = transform;
 }
 
 //Main function
 function Update (){
 
 if(open == true){
     var target = Quaternion.Euler (0, DoorOpenAngle, 0);
     // Dampen towards the target rotation
     myTransform.localRotation = Quaternion.Slerp(myTransform.localRotation, target, Time.deltaTime * smooth);
 }
 
 if(open == false){
     var target1 = Quaternion.Euler (0, DoorCloseAngle, 0);
     // Dampen towards the target rotation
     myTransform.localRotation = Quaternion.Slerp(myTransform.localRotation, target1, Time.deltaTime * smooth);
 }
 
 if(enter == true){
     if(Input.GetKeyDown("f")){
         open = !open;
         }
     }
 }
 
 //Activate the Main function when player is near the door
 function OnTriggerEnter (other : Collider){
 
 if (other.gameObject.tag == "Player") {
     (enter) = true;
 }
 }
 
 //Deactivate the Main function when player is go away from door
 function OnTriggerExit (other : Collider){
 
 if (other.gameObject.tag == "Player") {
     (enter) = false;
 }
 }
 
 
 
 
 
 
Comment
Add comment · Show 8
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 AeonIxion · Oct 25, 2012 at 06:41 AM 0
Share

Try using Lerp ins$$anonymous$$d of Slerp?

http://answers.unity3d.com/questions/299319/vector3slerp-problem.html

avatar image NewEonOrchestra · Oct 25, 2012 at 02:50 PM 0
Share

I looked up the difference and simply swapped the operations out, so now they are both Lerp. This does help a little... but I still suffer an enormous frame rate hit. Without the script I get a s$$anonymous$$dy 60 fps. With it I only get 13.

avatar image markpdolby · Oct 25, 2012 at 03:12 PM 0
Share

If you disable the collider on the door does it increase the performance?

avatar image NewEonOrchestra · Oct 25, 2012 at 03:19 PM 0
Share

Sadly that changes nothing. I am fairly confident the lag is co$$anonymous$$g from that Quaternion.slerp (or lerp) call, but I have no clue why it should. Surely this must be a commonly used line?

avatar image markpdolby · Oct 25, 2012 at 04:09 PM 0
Share

I tried your script in an empty scene attached to a cube and there was no noticeable change in frame rate, so maybe it is the door object itself which is causing the issue? Try attaching the script to a standard cube and see if you get the same results.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

12 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

Related Questions

Door opening with a key, my scripts and problem 1 Answer

my script not working..!!! 1 Answer

Script for a door that requires (9 papers) to open 0 Answers

Open/close door, lags if I walk into it. 0 Answers

How to make 2 doors with 2 diffrent keys 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