Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 BilboStabbins · Jun 07, 2014 at 05:01 PM · positionslow down

How to smoothly slow down a non-Rigidbody object

I was wondering how I would smoothly slow down/decelerate to a stop a non-rigidbody object moving in a particular direction.

Comment
Add comment · Show 1
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 Owen-Reynolds · Jun 07, 2014 at 06:49 PM 0
Share

If it's not a rigidbody, and is moving. It means that you're moving it, in your code, through some various means.

If you're adding 0.5 every frame, then figure out a way to add only 0.45, then 0.4 ... . If you're using a Lerp(start, stop, pct), and pct is increasing by 0.03 each frame, then figure out how to have that 0.03 drift down (maybe when it gets past 0.95?)

2 Replies

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

Answer by Jeff-Kesselman · Jun 07, 2014 at 07:05 PM

Another approach is to add in a fixed drag by taking a drag rate an s multiplying it by the elapsed time

 float drag=2.0; // drag per sec
 
 public void Update(){
    float elapsedDrag = drag * Time.deltaTime;
   if (rigid body.velocity.x>0) {
          rigidbody.velocity.x = Math.max(rigidbody.velocity.x-elapsedDrag,0);
   } else {
          rigidbody.velocity.x = Math.minn(rigidbody.velocity.x+elapsedDrag,0);
   }
   if (rigid body.velocity.y>0) {
          rigidbody.velocity.y = Math.max(rigidbody.velocity.y-elapsedDrag,0);
   } else {
          rigidbody.velocity.y = Math.min(rigidbody.velocity.y+elapsedDrag,0);
   }
   if (rigid body.velocity.z>0) {
          rigidbody.velocity.z = Math.max(rigidbody.velocity.z-elapsedDrag,0);
   } else {
          rigidbody.velocity.z = Math.min(rigidbody.velocity.z+elapsedDrag,0);
   }
 }

The max/min is to clip it at 0.

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 tanoshimi · Jun 07, 2014 at 07:06 PM 0
Share

Doesn't the OP say non-rigidbody?

avatar image Jeff-Kesselman · Jun 07, 2014 at 07:10 PM 0
Share

True, okay. Same thing but using your own velocity numbers.

avatar image BilboStabbins · Jun 10, 2014 at 12:21 AM 0
Share

Thanks for the suggestions.

Yes, it's a non-RB. Would you $$anonymous$$d, giving me an example of how to use this with a non-RB? I'm not having great success with describing the equivalent conditions to deter$$anonymous$$e the x, y, and z directions/movement (if .. > 0 , etc.) that it's moving in, in order to apply the correct position change.

avatar image
0

Answer by HammockHead · Jun 07, 2014 at 05:10 PM

I'd imagine you would interpolate between the rigidbody's current velocity to an end velocity (in this case a velocity of 0,0,0). Something like this could possibly work :

 function slowDown(endVeclocity:Vector3) {
     startVelocity = rigidbody.velocity;
     rigidbody.velocity = Vector3.Lerp(startVelocity,endVelocity,Time.deltaTime)
 }

You could of course add a float to the third parameter of the Lerp function to simulate acceleration. Just a warning, I haven't test this yet but it should at least give you an idea.

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

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

25 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

Related Questions

Camera rotation around player while following. 6 Answers

Object cannnot be transformed in start() 1 Answer

Recentering view/position with Oculus Rift DK2 in Unity 5? 1 Answer

How to write a script to disable position and rotation tracking for VR 0 Answers

Unity3D - Playback object array of position (with dynamic velocity) 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