• 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
Question by IamTabu316 · Dec 01, 2018 at 12:35 AM · objectrigidbody2dspeed

Slow down Rigidbody's speed to a stop

I'm trying to make my player slide a bit when the input key is let go and I want it to decrease over a few frames. How would I do this? Here's my movement code:

 float p = Input.GetAxisRaw("Horizontal");
             if( p > 0){
                 myRigidbody.velocity = new Vector3 (activeMoveSpeed, myRigidbody.velocity.y, 0f);
                 transform.localScale = new Vector3 (currentValue, currentValue, 1f);
             } else if (Input.GetAxisRaw ("Horizontal") < 0f) {
                 myRigidbody.velocity = new Vector3 (-activeMoveSpeed, myRigidbody.velocity.y, 0f);
                 transform.localScale = new Vector3 (-currentValue, currentValue, 1f);
             } else if(p <= 0)
             {
                //Slide code goes here
 
             }

Comment

People who like this

0 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 hexagonius · Dec 01, 2018 at 12:32 PM 0
Share

why don't you use a PhysicsMaterial which applies friction to it on it's own? Or use the rigidbodies drag value.

avatar image IamTabu316 hexagonius · Dec 01, 2018 at 07:06 PM 0
Share

I already have a different material attached to my player's rigidbody and the drag doesn't let my player jump properly

2 Replies

  • Sort: 
avatar image

Answer by Kudorado · Dec 03, 2018 at 01:42 AM

you can try this one :

     myRigidbody.velocity -= myRigidbody.velocity / 10f;




Comment
nicxellent5

People who like this

1 Show 2 · 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 Eno-Khaon · Dec 03, 2018 at 01:47 AM 1
Share

Another way of making a similar change:

 myRigidbody.AddForce(-myRigidbody.velocity, ForceMode.Acceleration);
avatar image IamTabu316 · Dec 03, 2018 at 03:28 AM 0
Share

@Kudorado Ok that works but now if I jump while idle it reduces the jump speed. How would I disable it when my player is not on the ground. (I already have a bool checking if it's on the ground or not)

avatar image

Answer by username123445 · Dec 01, 2018 at 07:47 PM

create friction in the code and don't apply it when you jump

Comment

People who like this

0 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 IamTabu316 · Dec 03, 2018 at 01:38 AM 0
Share

How exactly would I do that?

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

107 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 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 keep speed canstant in flappy bird? 2 Answers

Can we refer to two rigidbodies2d in a single script? 0 Answers

Putting a brakes on my spaceship 0 Answers

2D Sprite/object rotation changing despite telling it not to 0 Answers

DragObject Damping 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