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 Tea_Doogun · Dec 20, 2012 at 07:59 PM · vector3slerp

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

I simply want my 'character' to move upwards 10 meters when a racast hits a tagged object.

I'm using a Vector3.Slerp, i've tried AddForce, but found it too unpredictable.

My basic Slerp code is:

 function Update () {
 
 var x = transform.position.x;
 var z = transform.position.z;
 var y = transform.position.y + 10;
     
     var end = Vector3(x, y, z);    
 
 rigidbody.velocity = Vector3(0, 0, 0);
 transform.position = Vector3.Slerp(transform.position, end, Time.time * 0.5);
 
 }

The trouble is, the model 'teleports' from the starting position to the end position, no visible transition takes place!

It is a 3rd person game, my x, y, z variables make sure the character moves upwards relative to the current position of the character.

'He' has a rigidbody, NON-kinematic and uses gravity.

I tried temporarily disabling gravity, and also using Time.deltaTime in space of Time.time, the problem persists.

Anyone have any experience with this? Or know a better way to move the character?

Thanks as always for your help, Tom :)

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
3
Best Answer

Answer by sotirosn · Oct 28, 2013 at 07:00 PM

Lerp and Slerp functions take a value between 0 and 1. I think of this as the weight(and inverse weight) given to each vector v1 and v2 in.. Vector3 v = Vector3.Lerp(v1, v2, weight); // where if, weight = .25 -> v = (1-.25)*v1 + (.25)*v2

so before you enable Update you need to save the start time, subtract the current time from the start time, and divide by the duration over which you would like to animate.

 public class CharacterMove : Monobehaviour {
 public float moveSpeed;
 
 public void Awake() { enabled = false; }
 
 float startTime, duration;
 Vector3 startPoint, endPoint;
 public void StartMove(Vector3 endPoint) {
   // pre calc all the lerp parameters
   startPoint = transform.position;
   this.endPoint = endPoint;
   duration = (endPoint - startPoint).magnitude/moveSpeed;
   startTime = Time.time;
  
   enabled = true; // start updating the lerp
 }
 public void Update() {
    float time = Time.time-startTime; // time since start
 
   // interpolate position
   transform.position = Vector3.Lerp(startPoint, endPoint, time/duration);
 
   // full interpolation achieved
   if(time > duration) enabled = false;
 }  

This is just off the top of my head so there may be bugs but the comments explain what you are doing. If you would rather not split this move operation into a two separate function you need to learn about coroutines and IEnumerator functions.

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
-1

Answer by greatestprez · Dec 20, 2012 at 08:35 PM

Try using Vector3.Lerp instead

Comment
Add comment · Show 7 · 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 Tea_Doogun · Dec 20, 2012 at 08:40 PM 0
Share

Tried it, exactly the same result :(

Heh, should have mentioned in the post...will edit :)

avatar image greatestprez · Dec 20, 2012 at 08:42 PM 0
Share

Did you try Vector.Lerp with time.deltaTime?

avatar image Tea_Doogun · Dec 20, 2012 at 08:44 PM 0
Share

Won't let me edit...grr.

I did try Time.deltaTime.

avatar image greatestprez · Dec 20, 2012 at 08:49 PM 0
Share

Do you have any other scripts on your object?

avatar image Tea_Doogun · Dec 20, 2012 at 08:52 PM 0
Share

Yeah, moving, jumping, shooting.

Are there any scripts which interfere with Slerp/Lerp?

Show more comments

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

11 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

Related Questions

Vector3.Slerp problem 1 Answer

Transforming slowly 1 Answer

move object and slow down near end 1 Answer

Slerp to make the right/left side face another object 2 Answers

Interpolating along an arc. 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