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
1
Question by Brett_MMU · Aug 10, 2012 at 12:19 AM · vector3slerpnegative

Vector3.Slerp problem

Hello,

I have this bit of code, which should change the y co-ordinate (and nothing else) of the GameObject it's attached to.

 using UnityEngine;
 using System.Collections;

 public class slerpTest : MonoBehaviour {

 // Use this for initialization
 void Start () {
     transform.position = new Vector3(0,-20,0);
 }
 
 // Update is called once per frame
 void Update () {
      transform.position = Vector3.Slerp (transform.position, new Vector3(0,1,0), Time.deltaTime);
      Debug.Log (transform.position);
    }
 }

Now when I run this, the z co-ordinate is changing, which it shouldn't. I've noticed it only happens when I'm slerping from a negative y value to a positive y value. If I change the slerp code to

 transform.position = Vector3.Slerp(transform.position, new Vector3(0,0,0), Time.deltaTime);

then the z value doesn't change and it works as intended. I can't find any information anywhere on unity answers or google about problems regarding slerping from a negative value to a positive one.

Is it a bug? Is it normal behaviour? and is there a fix?

Thanks

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

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

Answer by aldonaletto · Aug 10, 2012 at 12:58 AM

I suspect you really want to use Lerp, not Slerp: Lerp returns a position on the line connecting the two points, while Slerp tries to return positions over a curve between the two points - and this curve may be very weird and unexpected depending on the distances of each point to the origin (0,0,0)

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 Brett_MMU · Aug 10, 2012 at 01:51 AM 0
Share

Thanks, when I use Lerp it works properly. I was somewhat surprised at it though as I regularly use Slerp in unity and have never come across this problem before.

avatar image aldonaletto · Aug 10, 2012 at 12:13 PM 0
Share

Slerp is a very weird and unpredictable function: it returns points of a curve passing through the two end points, but nobody knows which mysterious algorithm evaluates this curve - small differences may change it completely. I tested the two endpoints you're using, and when the second point was (0,0,0), the "curve" was a straight line; when changed to (0,1,0), it became an spiral running in the opposite direction!

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Input manager, how to use positive/negative 1 Answer

How can I create a follower Ai which is restricted on the Y Axis? 0 Answers

making a camera that moves depending on mousepos.y 0 Answers

Vector3.Slerp is 'jumping' from the begining to end position 2 Answers

Controlling the speed of Vector3.RotateTowards 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