• 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
1
Question by Baystep · May 04, 2015 at 10:10 AM · movementrigidbodythird-person

Rigidbody spins out of control

So I'm building a third-person character, say 3D platformer. I'm using a rigidbody and capsule collider. My problem is that whenever I jump, if I hit a corner of a cube, the rigidbody gets stuck to it's edge. And worse yet, it sometimes continues moving along the edge like it's locked to it. And even worse is if it does get dislodged from the edge, upon landing on the ground it starts spinning out of control. But weirdly enough I can kind of slow down the rotation using the controls, if I let go, it goes right back to the same spin speed. This seems to happen whenever the edge meets the rounded portion of the capsule collider. If it hits the flat surface it acts properly.

My left-right controls are supposed to rotate the player, with up and down being the forward or reverse velocities. Anyone else run into this, and how they might have solved it?

Here's some relevant code (I believe)

 //Here's the inputMovement line.
 inputMovement.Set(Input.GetAxis("Horizontal") * calculatedSpeed * 2f, 0f, Input.GetAxis("Vertical") * calculatedSpeed);
 
 public virtual void FixedUpdate() {
 
             curPosition = transform.position;
             curRotation = transform.rotation;
     
             forwardVector = transform.forward;
             forwardVector.y = 0f;
             forwardVector.Normalize();
     
             CheckGrounded();
     
             if(grounded) {
     
                 targetVelocity = forwardVector * inputMovement.z;
                 targetRotation = curRotation * Quaternion.AngleAxis(inputMovement.x, Vector3.up);
     
                 if(doJump) {
                     doJump = false;
                     isJumping = true;
                     rigidBody.AddForce(transform.up * calculatedJump, ForceMode.Impulse);
                     Debug.Log("Did jump!");
                 } else if(isJumping)
                     isJumping = false;
             }
     
             setVelocity = Vector3.Lerp(rigidBody.velocity, targetVelocity, Time.fixedDeltaTime * 5f);
             setVelocity.y = rigidBody.velocity.y;
             rigidBody.velocity = setVelocity;
             rigidBody.rotation = Quaternion.Lerp(rigidBody.rotation, targetRotation, Time.fixedDeltaTime * 5f);
         }

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 melkorinos · May 04, 2015 at 11:32 AM 0
Share

one of your problems might be solved if you add a physics material with 0 friction to the walls, not sure though

avatar image Baystep · May 06, 2015 at 01:54 AM 0
Share

@melkorinos I did actually. That helped the rigidbody from sticking to flat walls, but the corner problem still exists. I'll keep playing around with Physics $$anonymous$$ats though.

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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Movement with physics 1 Answer

Player is Speeding up in collisions 0 Answers

Movement using rigidbody.velocity to apply a constant force until stop 1 Answer

How to make brownian motion of a RigidBody animal AI? 1 Answer

Character controller or rigidbody? for skateboard 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