• 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 petrbena · Oct 06, 2014 at 09:24 AM · physics

How to make object stop faster

I have an object that I move using this function

 public void StartWalk(float direction)
 {
     movement = new Vector2(this.speed.x * direction, this.rigidbody2D.velocity.y);
 }

 private void FixedUpdate()
 {
     rigidbody2D.velocity = movement;
 }

It works fine but problem is that when I stop moving it, the object starts slowing down until it stops. This slow down takes very long and it travel a long distance until it stops. How can I make it stop faster? I don't want it to stop instantly, just faster, like if the surface was not like an ice :)

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 N1warhead · Oct 06, 2014 at 09:35 AM 0
Share

i'm not sure if 2D works the same as 3d. But in 3d, it's not very good to change the velocity as you can have undesired results.

you can replacing your fixed update stuff with a

rigidbody2D.AddRelativeForce = movement;

I would place this in Answer, but I've never done 2D, so I'm not sure if you can even do that.

Just trying to help.

IF IT WOR$$anonymous$$S - Please let me know so I can put it in Answer so people searching can get the correct answer.

Anyways, hope that works!

Adding Force will still take a second to stop, but it won't be like that.. (CHANGING $$anonymous$$ASS ON RIGIDBODY ALSO HELPS!!!!!) YOU COULD EVEN TRY JUST DOING THAT!

2 Replies

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

Answer by robertbu · Oct 06, 2014 at 03:48 PM

Assuming you don't have any other forces on it, just upping the 'Linear Drag' in the Rigidbody2D on the object should do the job. You might also consider creating and setting physic2D materials on the Collider2Ds of the sliding object and the surface. You can define the friction and bounciness for both colliders.

Comment
Add comment · Show 1 · 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 petrbena · Oct 07, 2014 at 07:13 AM 0
Share

friction does the job, there is no linear drag in 2d it seems

avatar image
5

Answer by LilGames · Jun 16, 2017 at 06:15 PM

The answer here is incorrect. The code shown by the OP is of very simple 2D sprite movement. The issue described stems from keyboard input that simulates the "return to center" of a joystick. A quick check of the default settings in:

Player Settings -> Input -> Horizontal / Vertical

...should reveal that the Gravity and Sensitivity of the keypress settings for Horz and Vert are set to 3 while other keys for "instant" actions like a Fire Button are set to 1000 !

The "gliding" being seen is the interpolation between the key being released and the system returning input to zero over a short amoutn of time. *(Where is this time configured??).

Go in and set Gravity and Sensitivty to 1000 and you'll see the sprite will now instantly stop when you release a keypress direction! Personally, I like a setting of 100 (so there's a little slow-down but not enough to feel "sloppy").

Modifying drag, friction etc like the accepted answer suggests will ALSO impact velocity and all other physics settings you already have related to the player movement and thus requires lots of re-tweaking to get everything right.

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

30 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

Related Questions

2D 360 degress platformer example needed 0 Answers

I have a sphere and a mesh (roulette table). Physics doesn't work. 2 Answers

How to Buffet an object floating in space? 1 Answer

Ball Bearing Simulation With Rigidbody's? 0 Answers

What is the best way to check is object intersecting? 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