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 dniwe_kore · May 23, 2020 at 06:09 PM · physicscollidermeshcollider

enabling mesh collider for rigidbody screws up everything

Hi. I have dummy rigidbody gameobject with disabled convex mesh collider, and some other stuff. Everything is good. I changed colliders matrix in project settings so my collider will not collide with anything in test. I have some code to add forces to rigidbody(thrust and torque). Literally everything works fine, until i enable collider - rigidbody almost stops receiving torque that applied from script(with collider enabled it has like 100x drag instead), and starts rotating by X and Z, while X and Z are frozen in constraints. I have no idea why enabling collider ruins everything. I made video: youtube. Here is my code of movement script.

 public class MController : MonoBehaviour
 {
     public Rigidbody rigidbodyDummy;
     public Transform pointer;
     public Properties props;
 
     //private Quaternion targetDirection;
     private Vector3 targetPoint;
     private bool isRotation = false;
     private bool isMovement = false;
     private bool isManeuvering = false;
 
     private float rotDelta = 0f;
     private bool isRotatingRight;
     public float distance = 0f;
     private float angVelocity;
 
     private float ex;
 
     public float velocity;
 
     public void CommandMoveTo(Vector3 point)
     {
         isManeuvering = true;
         isRotation = true;
         isMovement = true;
         targetPoint = point;
         //UpdateBrakes();
         //UpdateAngBrakes();
         ForceBrakes();
     }
     public void CommandRotateTo(Vector3 point)
     {
         isManeuvering = true;
         isRotation = true;
         isMovement = false;
         targetPoint = point;
         //UpdateAngBrakes();
         ForceBrakes();
     }
 
     void Start()
     {
         rigidbodyDummy.transform.SetParent(null);
     }
     private void FixedUpdate()
     {
         velocity = rigidbodyDummy.velocity.magnitude;
         velocity = Mathf.Round(velocity * 100f) / 100f;
         angVelocity = rigidbodyDummy.angularVelocity.y * Mathf.Rad2Deg;
         angVelocity = Mathf.Round(angVelocity * 100f) / 100f;
         angVelocity = Mathf.Abs(angVelocity);
         if (velocity != 0f || angVelocity != 0f)
         {
             transform.position = rigidbodyDummy.transform.position;
             transform.rotation = rigidbodyDummy.transform.rotation;
         }
         if (!isManeuvering)
         {
             return;
         }
         if (isRotation)
         {
             TryRotate();
         }
         if (isMovement)
         {
             TryMove();
         }
     }
     private void TryRotate()
     {
         Quaternion direction = Quaternion.LookRotation(targetPoint - rigidbodyDummy.transform.position); // get direction to point desired from current position
         rotDelta = Quaternion.Angle(rigidbodyDummy.transform.rotation, direction); // set initial rotation delta
         UpdateIsRotatingRight(direction);
         if (rotDelta <= 0.1f)
         {
             rigidbodyDummy.transform.rotation = direction;
             rigidbodyDummy.angularVelocity = Vector3.zero;
             if (isMovement == false)
             {
                 isRotation = false;
                 isManeuvering = false;
                 props.SetThrustFlame(0f, 4);
             }
             UpdateAngBrakes();
             return;
         }
         if (isRotatingRight)
         {
             rigidbodyDummy.AddRelativeTorque(Vector3.up * props.GetTorque() * GetTorqueMult());
             props.SetThrustFlame(GetTorqueMult(), 0);
         }
         else
         {
             rigidbodyDummy.AddRelativeTorque(Vector3.up * -props.GetTorque() * GetTorqueMult());
             props.SetThrustFlame(GetTorqueMult(), 1);
         }
         UpdateAngBrakes();
     }
     private void UpdateIsRotatingRight(Quaternion direction)
     {
         pointer.transform.rotation = rigidbodyDummy.transform.rotation;
         if (rotDelta < 165f)
         { 
             pointer.Rotate(Vector3.up * 0.01f);
             if (rotDelta < Quaternion.Angle(pointer.rotation, direction))
             {
                 isRotatingRight = false;
             }
             else
             {
                 isRotatingRight = true;
             }
         }
         else
         {
             pointer.transform.Rotate(Vector3.up * -0.01f);
             if (rotDelta < Quaternion.Angle(pointer.rotation, direction))
             {
                 isRotatingRight = true;
             }
             else
             {
                 isRotatingRight = false;
             }
         }
         pointer.transform.rotation = rigidbodyDummy.transform.rotation;
     }
     private float GetTorqueMult()
     {
         if(rotDelta > 15f)
         {
             return 1f;
         }
         else if(rotDelta > 0f)
         {
             float mult = rotDelta / 15f;
             mult = Mathf.Clamp(mult, 0.1f, 1f);
             return mult;
         }
         else
         {
             return 0f;
         }
     }
     private void UpdateAngBrakes()
     {
         if (rotDelta < 0.1f)
         {
             rigidbodyDummy.angularDrag = props.dragBase;
             return;
         }
         if (rotDelta > angVelocity)
         {
             rigidbodyDummy.angularDrag = 1f;
         }
         else
         {
             float newDrag = angVelocity * 0.5f;
             rigidbodyDummy.angularDrag = props.dragBase < newDrag ? props.dragBase : newDrag;
         }
     }
 
     private void TryMove()
     {
         distance = Vector3.Distance(rigidbodyDummy.transform.position, targetPoint);
         if (distance <= 1.0f)
         {
             isManeuvering = false;
             isMovement = false;
             isRotation = false;
             props.SetThrustFlame(0f, 4);
             UpdateBrakes();
             return;
         }
         if (rotDelta <= props.maxRotDeltaForMove)
         {
             rigidbodyDummy.AddRelativeForce(Vector3.forward * props.maxThrust * GetThrustMult());
             props.SetThrustFlame(GetThrustMult(), 2);
             UpdateBrakes();
         }
     }
     private float GetThrustMult()
     {
         if (distance > 10f)
         {
             return 1f;
         }
         else if (distance > 0f)
         {
             float mult = distance / 10f;
             mult = Mathf.Clamp(mult, 0.01f, 1f);
             return mult;
         }
         return 0f;
     }
     private void UpdateBrakes()
     {
         if (distance < 1.0f)
         {
             rigidbodyDummy.drag = props.dragBase;
             rigidbodyDummy.angularDrag = props.dragBase;
             return;
         }
         if (distance > velocity)
         {
             rigidbodyDummy.drag = 1f;
         }
         else
         {
             float newDrag = velocity * 0.5f;
             rigidbodyDummy.drag = props.dragBase < newDrag ? props.dragBase : newDrag;
         }
     }
     private void ForceBrakes()
     {
         rigidbodyDummy.drag = 1f;
         rigidbodyDummy.angularDrag = 1f;
     }
 }


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 dniwe_kore · May 23, 2020 at 06:11 PM 0
Share

damn i thought it is shorter

avatar image dniwe_kore · May 23, 2020 at 06:37 PM 0
Share

mesh collider causes rigidbody to rotate by frozen axis: alt text

screenshot-31.png (38.7 kB)

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.

Follow this Question

Answers Answers and Comments

236 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

Related Questions

HELP ME!! importing stuff!!! 2 Answers

Rigidbody projectile gets stuck in two-sided Procedural mesh / mesh collider 0 Answers

Question on Collider Resource Consumption 0 Answers

Wheel has no friction on mesh collider of another GameObject. 0 Answers

Mesh Collider won't draw the mesh I am telling it to? 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