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 Reaper1121 · Sep 03, 2015 at 03:16 PM · c#vector3.slerp

Vector3.Slerp is not working help.

Hello i want to rotate object y0 to y90 but it does not work this is what i tried:

 using UnityEngine;
 using System.Collections;
 
 public class OpenDoor : MonoBehaviour {
 
     public bool isdooropen = false;
     private float dooropensmoothness = 2f;
 
     // Use this for initialization
     void Start () {
 
     }
     
     // Update is called once per frame
     void Update () {
     
         if (isdooropen == true) {
 
             Vector3 DoorOpenAngleTo = new Vector3 (0,90,0);
 
             transform.rotation = Vector3.Slerp (transform.rotation.y, DoorOpenAngleTo.y, dooropensmoothness * Time.deltaTime);
 
         } else if(isdooropen == false){
 
             //transform.Rotate (new Vector3(0,10,0) * dooropensmoothness * Time.deltaTime);
 
         }
 
     }
 }
 

I tried everything but nothing works... can you stell me how to fix this slerp? this is what i want to happen: https://www.youtube.com/watch?v=xcWlXRESo-8 but the video gives errors soo i am trying to use vector3.slerp to fix this.

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

2 Replies

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

Answer by Positive7 · Sep 03, 2015 at 03:49 PM

 void Update () {
         
         if (isdooropen == true) {
             
             Quaternion DoorOpenAngleTo = Quaternion.Euler(0f,90f,0f);
             
             transform.rotation = Quaternion.Slerp (transform.rotation, DoorOpenAngleTo, dooropensmoothness * Time.deltaTime);
             
         } else{
             Quaternion DoorOpenAngleTo = Quaternion.Euler(0f,0f,0f);
 
             transform.rotation = Quaternion.Slerp (transform.rotation, DoorOpenAngleTo, dooropensmoothness * Time.deltaTime);
             
         }
         
     }
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 Suddoha · Sep 03, 2015 at 04:15 PM 0
Share

This is actually not quite correct. It appears to work, but it's not the correct usage of neither Lerp nor Slerp. $$anonymous$$any people do exactly that with Lerp, which turns out to have some kind of fade-out effect, but that's actually not what the method is about.

See @OG23 answer for clarification.

avatar image Reaper1121 · Sep 03, 2015 at 04:23 PM 0
Share

Thanks. I cannot accept 2 questions as the best answer. Thanks to both of you guys.

avatar image
1

Answer by hulahoolgames · Sep 03, 2015 at 03:59 PM

I can see a few problems with your code, correct me if I am wrong:

  1. Vector3.Slerp takes in two vectors and spherically interpolates between them. You are passing two floats to this function. Also note, Slerp treats these vectors as directions and not positions in space like Lerp.

  2. You are setting a Quaternion, transform.rotation but Vector3.Slerp returns a Vector3. You should be seeing errors in your console for these 2 problems.

  3. Try using Quaternion.Slerp instead.

  4. The Slerp function moves from a to b within time t. So when t = 0 the value returned should be a and when t = 1 the value returned should be b. See the Unity example in Vector3.Slerp. They have a total time in which they want to move from source to destination, called "journeyTime" and they store the "startTime". During Slerp, they pass the fracComplete value. This is what you should be using to pass as the last parameter in Slerp functions.

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 Reaper1121 · Sep 03, 2015 at 04:23 PM 0
Share

Thanks. I cannot accept 2 questions as the best answer. Thanks to both of you guys.

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

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Making a bubble level (not a game but work tool) 1 Answer

An OS design issue: File types associated with their appropriate programs 1 Answer

Renderer on object disabled after level reload 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