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 Heffalus · May 13, 2015 at 08:30 PM · c#vector3quaternionslerp

move object and slow down near end

I have a spaceship flying in towards a planet (Sphere), rotating and landing. Its working fine, i just want a litle better, im using the Vector3.Slerp and Quaternion.Slerp so that it slows down as it nears the landing spot. But it slows down too mutch, at the end its sooo slow to rotate and land. Any way to make it slow down...slower?

this is the code im using

 transform.position = Vector3.Slerp (transform.position, landingSpot, flightSpeed * Time.deltaTime / 100);
             if (Vector3.Distance (transform.position, landingSpot) < rotateForLandingDistance) {
                 transform.localRotation = Quaternion.Slerp (transform.rotation, landingRotation, rotationSpeed * Time.deltaTime / 100);
             }

Comment
Add comment · Show 2
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 $$anonymous$$ · May 13, 2015 at 08:34 PM 0
Share

Have you tryied to change the third Lerp param to higher values?

avatar image Heffalus · May 13, 2015 at 08:42 PM 0
Share

Doesnt work, then it just goes faster in the start.

1 Reply

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

Answer by $$anonymous$$ · May 13, 2015 at 09:45 PM

Time for a slightly more complex answer then! This is by no means the simplest solution but it is probably one of the most flexible.

By making use of animation curves one can draw a curve (in the editor) to manipulate the speed of an object. Below is a simplified version of a script that does that. If you want to actually use this you will probably want to make changes to script and include a base speed to prevent not moving but this will allow you to achieve the variable speed affect you would like.

I'll post the script below but you may want to check out these pages for reference:

  • http://docs.unity3d.com/ScriptReference/AnimationCurve.html

  • http://docs.unity3d.com/Manual/EditingCurves.html

The actual script:

 using UnityEngine;
 using System.Collections;
 
 public class SlerpTowards : MonoBehaviour
 {
     public Transform Target;
     public AnimationCurve DistanceVersusSpeed;
 
     private float _initialDistanceToTarget;
     private float _speed;
     private float _distanceToTarget;
 
     public void Start()
     {
         _initialDistanceToTarget = (Target.position - transform.position).magnitude;
         _speed = 0;
     }
 
     public void Update()
     {
         // Calculate our distance from target
         Vector3 deltaPosition = Target.position - transform.position;
         _distanceToTarget = deltaPosition.magnitude;
 
         // Update our speed based on our distance from the target
         _speed = DistanceVersusSpeed.Evaluate((_initialDistanceToTarget - _distanceToTarget) / _initialDistanceToTarget);
 
         // If we need to move father than we can in this update, then limit how much we move
         if (_distanceToTarget > _speed)
             deltaPosition = deltaPosition.normalized * _speed;
 
         // Set our position
         transform.position += deltaPosition * _speed * Time.deltaTime;
     }
 }

Comment
Add comment · Show 3 · 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 Heffalus · May 13, 2015 at 10:51 PM 0
Share

thank you, this was perfect

avatar image Heffalus · May 13, 2015 at 11:07 PM 0
Share

Is this possible to do for the rotation aswell?

avatar image $$anonymous$$ · May 14, 2015 at 04:04 PM 0
Share

This could potentially work for changing any variable you wanted. Animation curves just allow you to "animate" a float. What you choose to do with that float is up to you.

You'll note that in the above example I used the animation curve to animate my _speed variable. I then used this as the rate for which the object moved.

Something along the lines of

 transform.rotation += (angle) * _speed * Time.deltaTime

would work for rotation, and more generically:

 object.thingToChange += amountToChange * _speed * Time.deltaTime

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

19 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

Related Questions

Slerp look at direction not working... 3 Answers

calculating looking angle between 2 transforms 0 Answers

Distribute terrain in zones 3 Answers

Quaternion Smooth Rotation 0 Answers

Slerp to make the right/left side face another object 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