• 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 CoreyC23 · 5 days ago · collisionrigidbodyplayer movementjitterrigidbody.moveposition

Rigidbody Jittery Collision

Hello!


I am a Unity beginner / intermediate trying to set up a very basic player controller using a Rigidbody. However, when testing the controller, collision against any obstacle results in a very jittery behavior, as if the object was being placed inside of the object and rocketed back out. Described behavior is shown below in a gif, alongside my game objects' settings and code. I am using MovePosition() on the Rigidbody to generate the movement, and the Input System package from Unity to control player input.


I've been looking around for a few hours now, messing with various settings, and the common fixes and forum posts don't seem to be working. Here are a few things I have tried:

  1. Difference between Update() and FixedUpdate(). The movement calculations are done in Update(), and the application of them / physics based items are done in FixedUpdate().

  2. Checking interpolation and collision detection methods under the Rigidbody. I have tried every combination of both (for example, Continuous + Interpolate, Discrete + None, etc.).

  3. Make sure "IsKinematic" is false. It is (I have also tried it as true).

  4. Apply frictionless Physic material to collision (I have tried with the material both on and off the object).

  5. Don't modify the position of the object in any way except through Rigidbody modifications.


Everything I am doing should be very simple, and stuff I've done before with no problems. Here is the exact path I took to recreate this problem, if it helps:

  1. Create new empty game object called "Player"

  2. Add "PlayerController.cs" script I made to this new game object (code given below) and set "Speed" to 10.

  3. Add a PlayerInput component from the input system package. Drag in my custom input actions asset, set the behavior to invoke Unity events, drag my script into the object space for the "Movement" input action (a simple Vector2 input axis bound to WASD) and choose my OnMovement() function to subscribe to the event.

  4. Add a Capsule Collider component; leave it with default settings.

  5. Add a Rigidbody component. Change "Interpolate" to "Interpolate", "Collision Detection" to "Continuous", and freeze the rotation on the X, Y, and Z axes.

  6. Add a 3dObject -> Cube child to "Player"; remove the box collider.

  7. Add two 3dObject -> Cube to the scene as a ground and floor.

  8. Test it out, and see unfortunate behavior :(


I've been banging my head against the wall for a good bit now. I suppose I could do some sort of Raycast to manually check for collisions, but I'd much rather get it working this way. If you need any further clarifications, screenshots, or descriptions of behavior, just let me know and I'll be happy to provide them. Any help would be greatly appreciated. Thank you in advance!


Gif of the undesired behavior:
Click me!!!
Player game object inspector screenshot:
alt text
alt text
Code of undesired behavior:

 using UnityEngine;
 using UnityEngine.InputSystem;
 
 public class PlayerController : MonoBehaviour
 {
 
     // Variables
     public float speed;
     private Rigidbody rb;
     private Vector2 moveInputAxes;
     private Vector3 moveAmt;
 
     // Start, set reference to the Rigidbody component
     private void Start()
     {
         rb = GetComponent<Rigidbody>();
     }
 
     // Update, calculate movement
     private void Update()
     {
         moveAmt = new Vector3(moveInputAxes.x, 0, moveInputAxes.y) * speed * Time.deltaTime;
     }
 
     // FixedUpdate, apply movement
     private void FixedUpdate()
     {
         rb.MovePosition(rb.position + moveAmt);
     }
 
     // PlayerInput callback, read value for use in Update
     public void OnMovement(InputAction.CallbackContext value)
     {
         moveInputAxes = value.ReadValue<Vector2>();
     }
 
 }
 


screenshot-20230314-063655.png (70.2 kB)
screenshot-20230314-063705.png (25.9 kB)
Comment

People who like this

0 Show 0
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

Answer by Mr_Potato342 · 4 days ago

you are using rb.MovePosition? I have not seen anyone do that but should not be a problem, try changing the collison detection mode to continuous dynamic, has fixed many things for me

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 CoreyC23 · 3 days ago 0
Share

Yes, I am using rb.MovePosition. I am going for a top-down 2.5d-style game, and would like the movement to be very immediate with no acceleration / decelleration (just instant velocity changes); it's not very realistic, but in the games I've played with this style of movement, it has made me feel like I'm in complete control of the player, and never slipping around. Most of the tutorials / posts I saw replicating this type of movement used rb.MovePosition, so I went with that; if there is another way to accomplish this type of movement (that isn't just emulating instantanous velocity change, such as AddForce with a high drag), I'd be happy to just switch to that instead. I've already tried setting the collision detection mode to continuous dynamic; the same sort of behaviour unfortunately persists with little to no change. Using rb.AddForce works as intended, and actually works quite well, using pretty much the same code as above. If I can't solve this problem, then I might just switch over to that instead. I'd still really like to know why MovePosition isn't behaving as expected, though, so that I may see if it works better for the feel of my game, and so that I can use it correctly in the future for other projects.

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

270 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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 get transform.Translate to work with rigidbodies 2 Answers

Stop rigidbody player from juddering when walking into a wall. 0 Answers

Custom Player Controller Ground Warping *SOLVED* 1 Answer

How do I stop my player or camera from jittering during player movement? 1 Answer

Player falling through the floor 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