• 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 Feref2 · Aug 01, 2017 at 05:09 PM · force

Slow down force/movement

I need to slow down an object when an applied force to its rigidbody stops. I´ve managed to stop that force on time, but then it has like a residual impulse, so it reaches further (much more than is supposed to, like the triple). The only solution that came to my mind was to reduce the impulse´s speed. It worked, but I don´t want that. What I need is to move it very fast and then slow down, with just a little bit of smooth movement after cutting that impulse.

Thanks for your time.

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
1

Answer by TheSOULDev · Aug 01, 2017 at 05:53 PM

Create a boolean that tells you whether the object is receiving force or not. Then, create 2 scenarios with and if and else statement - where it's receiving force and where it isn't; if it's receiving force, do nothing, if it's not, add a constant force in the direction opposite of the last direction where you added force which will slow it down until it stops. You will need to record the vector of the force you're adding every update and reverting the direction is literally multiplying it by -1. If you need the object to have stopping path of constant length for every velocity, then the coefficient with which you'll be adding the new force with will be dependent on the speed you start slowing down from.

Finally, as it is almost impossible to hit a spot where your speed will be 0, you can calculate how long the stopping path will take. This is simple physics, and I've done something similar with my touch to move system in a game, you can see that here:

 void FindMovementVector (Vector2 location)
     {
         location -= new Vector2 (gameObject.transform.position.x, gameObject.transform.position.y);
         stoppingPath = (charRB.velocity.sqrMagnitude) / (Stats.charAccel * Stats.SlowdownCoefficient * 2);
 
         if(!State.disableFurtherVectoring && location.magnitude > stoppingPath)
             InputVector = location.normalized;
         else
         {
             InputVector = Vector2.zero;
             State.disableFurtherVectoring = true;
         }
     }

You can do this with force as well, but you're going to have to modify the physical equation for it with force instead of like me who used velocity. My equation comes from 2as = v^2, which means that s, or the stopping path is equal to v^2/2a, where a is the acceleration equal to the character acceleration times the character slowdown coefficient (I wanted my character to slow down quicker than it builds speed).

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
0

Answer by tudorel1 · Jul 03, 2018 at 08:14 PM

If I understand your wish correctly, the answer is simple:

Add some Drag to the Rigidbody of your gameObject,

Alternatively, you can slow down the velocity of your object over time from within a script.

 void Update() {
     GetComponent<RigidBody>().velocity *= 999f/1000f;
 }
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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

69 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to implement Mob movement / death ? 1 Answer

AddForce to object 3 Answers

Obtaining current forces being applied to a joint for visualization. 1 Answer

adding force to instantiated ragdoll 4 Answers

Firing projectile in curve 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