• 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 boddole · Jul 14, 2014 at 01:14 PM · movementphysicsrigidbody

Strange Rigidbody Behavior

Hello everyone, I've noticed a strange behavior from a rigidbody movement script I have created. Essentially, when the rigidbody is moving at certain angles, the rigidbody will begin to drift away from its intended line of travel (even when floating with no gravity. The example picture shows the approximate line of travel, beginning along the rectangle's angle (160 degrees) and then drifting along a sloped path away from the wall as time goes on. Note that this does not occur when moving North, South, East, or West (or seemingly even nw,ne,sw,se), and that the rigidbody always continues to move forward (it just begins to drift).

I've tracked the line of code that makes this happen down to:

             if (speedClamp) //player can move in x and z axis only, 
             {
                 playerVector.z = Mathf.Clamp (playerVector.z, -playerMaxForwardSpeed, playerMaxForwardSpeed);
                 Debug.Log ("playerVector.z is: " + playerVector.z);
 
                 playerVector.x = Mathf.Clamp (playerVector.x, -playerMaxForwardSpeed, playerMaxForwardSpeed);
                 Debug.Log ("playerVector.x is: " + playerVector.x);
             }

If: playerVector.x = Mathf.Clamp (playerVector.x, -playerMaxForwardSpeed, playerMaxForwardSpeed); is commented out, the rigidbody moves correctly (never drifting away from its intended path), while the line for playerVector.z does not prevent the rigidbody from moving properly.

I'm quite confused as to why this is occurring, so if anyone has an idea, I would be grateful to know about it.

alt text

example.png (234.8 kB)
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 awest · Jul 14, 2014 at 01:41 PM 0
Share

What method do you use to actually move the object?

Also, I've often experienced issues with jitter and path problem trying to move a box collider with rigidbody if there are any inclines.

avatar image boddole · Jul 14, 2014 at 01:57 PM 0
Share

I'm changing the rigidbody velocity directly (I know the manual includes a caution about this, but I'm not looking for true realism and I'm getting the behavior I want out of it).

I actually think I've just about got this figured out (I hope because I'm up way to late at this point), its just another simple error I missed because I was looking for a complex answer -> Depending on the direction of travel, the X or Z direction would max out, but the lesser value would just continue to increase (hence the weird drifting). Now, when one of the values max out, the smaller value stops growing, problem solved.

0 Replies

· Add your reply
  • Sort: 

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

23 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Force to Velocity scaling? 2 Answers

RigidBody Script Conflict 1 Answer

Camera Following Rigidbody 0 Answers

Rigidbody Not Sliding Down Slopes 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