• 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 khryus · Jun 07, 2018 at 08:11 PM · movementphysicsconstant

How can I make a rigidbody stop with the user input and ignore its kinetic energy?

My goal is to move the character (currently a capsule) at constant/fixed speed in the direction the player wants to. When the player stops giving inputs, the character should instantly stop moving, however it currently keeps "sliding away" when I drop inputs because it has gained kinetic energy. How can I make it ignore that energy and stop it right away?


Controller script:

     // the player willingly moves and rotates according to camera rotation 
     // I have also set constraints on the X and Z rotation values on the rigidbody component
     // this is a third person view game
     private void FixedUpdate()
     {
         rotate();
         Vector3 vert = getAxis("Vertical") * cameraTransform.forward;
         Vector3 horz = getAxis("Horizontal") * cameraTransform.right;
         rb.AddForce((vert + horz).normalized * speed, ForceMode.Impulse);
     }
 
     // todo: look towards the movement vector, reset to camera fwd when there is no movement
     void rotate()
     {
         Vector3 lookpos = transform.position + cameraTransform.forward;
         lookpos.y = transform.position.y;
         transform.LookAt(lookpos);
     }

     int getAxis(string name)
     {
         return Input.GetAxisRaw(name) > 0 ? 1 : Input.GetAxisRaw(name) < 0 ? -1 : 0;
     }

Properties of the character's rigidbody:

alt text

I have also attached a Physics Material to the character's Capsule Collider:

alt text

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Kciwsolb · Jun 07, 2018 at 09:40 PM

rb.velocity = Vector3.zero;

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

172 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 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

Is mixing movement types a bad thing to do? (Force and Translate) 1 Answer

Player gets stuck into object when it collides with it 0 Answers

Object attached to player doesn't collide 0 Answers

Using Rigidbody.MovePosition With Local Position and Lerp 2 Answers

How does Rigidbody.MovePosition works ? What's behind the API? 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges