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 /
avatar image
0
Question by suIly · Jul 30, 2019 at 11:00 PM · rigidbodycontrollerslope

Rigidbody bumping when going down slopes

My rigidbody controller goes fine up a slope, but when I go down it, it bumps around. My collider is smooth around the edges. I use Rigidbody.MovePosition to move the player.

What is happening?

Comment
Add comment · Show 5
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 Magso · Jul 30, 2019 at 11:57 PM 0
Share

This usually happens when moving the rigidbody on a global axis ins$$anonymous$$d of it's local axis. Also is is$$anonymous$$inematic set to true?

avatar image Cornelis-de-Jager · Jul 31, 2019 at 10:14 PM 0
Share

Can you add code for your movement controller.

avatar image suIly Cornelis-de-Jager · Aug 01, 2019 at 10:00 AM 0
Share

Yes, but it's over 500 lines long, so I'll just give you the movement stuff

avatar image suIly Cornelis-de-Jager · Aug 01, 2019 at 10:01 AM 0
Share
         Vector3 movement = transform.forward * $$anonymous$$ovementInputValue * -moveSpeed * Time.deltaTime;
         Vector3 finished$$anonymous$$ovement = rb.position + movement;
         if (which$$anonymous$$ovement == movementType.rb$$anonymous$$ovePosition)
             rb.$$anonymous$$ovePosition(new Vector3(finished$$anonymous$$ovement.x, transform.position.y, finished$$anonymous$$ovement.z));
         else if (which$$anonymous$$ovement == movementType.rbAddRelativeForce)
             rb.$$anonymous$$ovePosition(new Vector3(finished$$anonymous$$ovement.x, transform.position.y, finished$$anonymous$$ovement.z));
avatar image Cornelis-de-Jager suIly · Aug 02, 2019 at 12:25 AM 0
Share

Ins$$anonymous$$d of using RigidBody.$$anonymous$$ovePosition alone. You can use a lerp function to make it smoother.

 `Rigidbody.$$anonymous$$ovePosition (Vector3.Lerp (rb.position, finished$$anonymous$$ovement, 1f));`

3 Replies

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

Answer by Cornelis-de-Jager · Aug 02, 2019 at 12:37 AM

Instead of using RigidBody.MovePosition alone. You can use a lerp function to make it smoother.

 Rigidbody.MovePosition (Vector3.Lerp (rb.position, finishedMovement, 1f));
 

Alternatively you can move the object along the slope rather than the forward position.

 HitInfo GetFloor() {
     // Do raycast to get floor
     Ray ray = new Ray (transform.position, vector3.down);
     
     HitInfo hit;
     
     Physics.Raycast (ray, out hit);
     
     return hit;
 }
 
 Vector3 GetMoveDirection () {
     var forward = transform.forward;
     var floor = GetFloor();
     
     if (floor.transform == null)
         return forward;
         
     var normal = floor.Normal;
     var moveDir = new Vector3 (forward.x, -normal.y, for .z);
     
     return moveDir.Normalize();
 }
 
 ...
 Vector3 movement = GetMoveDirection () * MovementInputValue * -moveSpeed * Time.deltaTime;
 Vector3 finishedMovement = rb.position + movement;
 if (whichMovement == movementType.rbMovePosition)
     rb.MovePosition(new Vector3(finishedMovement.x, transform.position.y, finishedMovement.z));
 else if (whichMovement == movementType.rbAddRelativeForce)
     rb.MovePosition(new Vector3(finishedMovement.x, transform.position.y, finishedMovement.z));
Comment
Add comment · Show 3 · 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 suIly · Aug 02, 2019 at 09:29 AM 0
Share

Thanks a lot!

avatar image suIly · Aug 02, 2019 at 09:30 AM 0
Share

Is this javascript? I need to translate this to c#

avatar image Cornelis-de-Jager suIly · Aug 04, 2019 at 09:19 PM 0
Share

No its C#, the bottom part should just replace some of the code you provided.

avatar image
0

Answer by suIly · Jul 31, 2019 at 10:09 PM

No, isKinimatic is set to false. Also, how do I move on the local axis, not the global axis?

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 Magso · Jul 31, 2019 at 10:21 PM

In the docs for MovePosition it states that in order for a smooth transition it needs to be kinematic but that would be used for something like for example a 3rd person platformer enemy. A rigidbody ideally needs AddRelativeForce.

Comment
Add comment · Show 13 · 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 suIly · Jul 31, 2019 at 11:27 PM 0
Share

Thanks! The player movement is a lot smoother! What is the difference between the $$anonymous$$ovePosition and AddRelativeForce?

avatar image suIly suIly · Jul 31, 2019 at 11:27 PM 0
Share

I'm making a tank multiplayer game btw

avatar image Magso suIly · Aug 01, 2019 at 12:40 AM 0
Share

Basically $$anonymous$$ovePosition(Vector3.forward) is teleporting the rigidbody forward then relying on the physics to correct it afterwards. AddRelativeForce moves the rigidbody using the physics engine. $$anonymous$$ovePosition is better for is$$anonymous$$inematic which is like a rigidbody ignored by the physics engine but has methods which allow it to affect and react with other rigidbodies.

avatar image suIly · Aug 01, 2019 at 12:37 AM 0
Share

link text

The tank still bumps around when going downhill...?

avatar image Magso suIly · Aug 01, 2019 at 12:44 AM 0
Share

How is the tank's hierarchy set up?

avatar image suIly Magso · Aug 01, 2019 at 09:50 AM 0
Share

Tank Hierarchy

Show more comments

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

156 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

Related Questions

Stick player (my own rigidbody controller) to the ground when going down the slope 2 Answers

MMD How to export model and animations to Unity as 3rd person controller? 2 Answers

turn on and off character controller 0 Answers

Platforming - moving up sloped surfaces ? 0 Answers

How can I change my movement scripts so it moves by rigidbodies movement so it doesn't clip 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