Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Lemaw · Sep 12, 2015 at 09:43 AM · c#movementrigidbody

How to make Rigidbody movement not slippery?

I already try changing the speed changing the ForceMode changing the rigidbody mass and drag, nothing seems to make the movement "responsive", all these does is making the character feels "heavier" or "lighter".

Here's the movement script

 using UnityEngine;
 using System.Collections;
 
 public class Movement : MonoBehaviour
 {
     public float speed = 10f;
     private Rigidbody rb;
 
     void Awake()
     {
         rb = GetComponent<Rigidbody>();
     }
 
     void FixedUpdate()
     {  
         float moveHorizontal = Input.GetAxis("Horizontal");
         float moveVertical = Input.GetAxis("Vertical");
         Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical).normalized;
         rb.AddForce(movement * speed * Time.fixedDeltaTime, ForceMode.Impulse);
     }
 }
 
Comment
Add comment · 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 Owen-Reynolds · Sep 12, 2015 at 04:17 PM 0
Share

I'm not sure what you mean by "slippery," and how to relates to the other word you use, "responsive." Do you mean it feels like Asteroids, where it takes a while to change direction?

But since you wrote slippery in the title: the slipperiness of rigidbodies is controlled by Physics $$anonymous$$aterials.

avatar image Lemaw Owen-Reynolds · Sep 12, 2015 at 06:59 PM 0
Share

Yes, "slippery" like Asteroid.

With my original code, if i set the Rigidbody mass to low number it will have fast acceleration but will take long time before it stopped. I want to make it have fast acceleration and fast deceleration.

4 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by DoTA_KAMIKADzE · Sep 12, 2015 at 09:48 AM

My guess is that you have no idea when you should use AddForce, am I right? If yes, then just replace your line#19 (rb.AddForce) with that one:

 rb.velocity = movement * speed;
Comment
Add comment · Show 4 · 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 Lemaw · Sep 12, 2015 at 06:57 PM 0
Share

yes you're right, i don't even know what AddForce do actually, i just used it because some of the tutorials i see are using it. :D

Thanks for your suggestion your code works nicely, but when i let go the movement button the character still moving for a while before it stop (like there's a lag). Can something be done to prevent this?

avatar image SarperS Lemaw · Sep 12, 2015 at 07:06 PM 0
Share

If there is no input set the velocity to Vector3.zero

avatar image DoTA_KAMIKADzE Lemaw · Sep 12, 2015 at 07:47 PM 0
Share

Depends on implementation of your input, but considering your comment, you should check out Input $$anonymous$$anager THERE (e.g. my one more guess would be that if you'll set gravity of your both axis there to something like 9000 then it will work as you expect, now in order to understand what it does follow the link that I've provided).

Alternatively you can do what Sarper Soher has suggested you to do. There are also plenty of other ways to do the same, as I said at the beginning that mostly depends on your implementation and what variety of behaviors you expect in the end.

avatar image MentorMatt · Jul 26, 2018 at 05:04 AM 0
Share

thanks a lot. been a rough transition from in-game level editors to c#. i have no idea what i'm doing lol. now how do i make gravity affect velocity.....

avatar image
0

Answer by Cherno · Sep 12, 2015 at 08:06 PM

In FixedUpdate, at first, set the RB's velocity to Vector3.zero. After that, use Transform.Translate to set the desired movement vector.

Note 1: Many users say that Translate shouldn't be used with RB movement, but I haver never had any problems with it, and it is also used in at least one comprehensive RB movement tutorial. Note 2: If the RB is being affected by other phyics (explosions, being pushed etc), this needs to be suspended temporarily, of course.

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 Moohasha · Sep 12, 2015 at 10:20 PM

Adding force to a Rigidbody means you are using the physics engine to move a GameObject. In real life (ie, using physics), when you move an object you apply a force to it and it accelerates to a point where the dynamic friction of the surface it is moving over prevents it from accelerating any further. Sometimes this acceleration appears very sudden, like when a sprinter shoots off the starting blocks, but it's still a gradual acceleration from no velocity to fast velocity.

I suggest either not using the Rigidbody to move your GameObject (just translate the Transform manually) or specify VelocityChange as the ForceMOde when you call AddForce(). VelocityChange means you are immediately changing the velocity to something else, ignoring mass and acceleration. You can use this to immediately begin moving at some velocity or to immediately stop.

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 PuzzleBuilder · Jan 02, 2017 at 08:25 AM

In the input manager, increase the gravity for the vertical and horizontal axis inputs. I did this while using the movePosition function, and it worked well. I think it would also help in your case.

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 Owen-Reynolds · Jan 02, 2017 at 04:12 PM 0
Share

Gravity in the input manager is really for beginners using keyboard input and a simple "speed=an-axis" code line. Then, ins$$anonymous$$d of having to code yourself "push key = gradual speed up; let go of key = slow down," you can use the Input manager sliders. It's mostly used to tweak the standard character controller script.

If you use Addforce on a rigidbody (like the poster is,) you're already coding the gradual speed increase/decrease. Also using input manager settings is driving like a car with two steering wheels. It's simpler to just code with keyDown and ignore axises (and for tablets, you have to do that anyway,)

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Acceleration only increasing when I press a key 0 Answers

Rigidbody movement instead of transform? 0 Answers

Issues Getting my GameObject to both Move Forward and Jump properly. 0 Answers

Rigidbody movement: Changing the Y of transform.position makes my character stutter 0 Answers

Jump is higher then normal 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