Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Rigidbody Box Collider Going through MeshCollider Walls on 5.0

Discussion in 'Physics' started by ippdev, Mar 5, 2015.

  1. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,789
    I upgraded my clients game from 4.6.3 to 5.0 and the BoxCollider based vehicle goes through the MeshCollider walls. I tried setting the MeshCollider as Convex and that did not work. I tried both Kinematic and non Kinematic settings on the Rigidbody BoxCollider and they will collide with BoxColliders (other traffic) but Kinematic makes the other vehicle disappear at collision!!! Non Kinematic collisions pushes the driver BoxCollider through the roads BoxCollider surface. I see very few answers here in this forum. Should I revert back to 4 and lose all the changes to the tracks and code? I do not want to look like an idiot to this client and need to get paid.
     
  2. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    how are you moving your box collider?
     
  3. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,789
    Works fine in 4.6.x

    Code (JavaScript):
    1. rigidbody.MovePosition(rigidbody.position + (transform.forward * currSpeed) * Time.deltaTime);
    .

    Below it added a GetComponent every loop on 5.0.0f4

    Code (JavaScript):
    1. GetComponent.<Rigidbody>().MovePosition(GetComponent.<Rigidbody>().position + (transform.forward * currSpeed) * Time.deltaTime)
    But the vehicle still moves properly..It is the collisions are all screwy. Change the wall mesh collider to convex and they flatten out and elongate to about 200% of the track length. Doesn't change a thing. Did solve the issue of the rigidbody box collider pulling to the right about 30 seconds into the sim. What collisions did register were like 100x the 4.x physX values.
     
  4. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    Well, I fired up U5 for the first time tonight, thought I would try convert a little side project, very basic physics setup as im aiming at mobile. Physics movement is by the same method you use MovePosition, worked sweet in U4. To give some context these are slow moving vehicles as well.

    I have a simple terrain setup, 1000x1000, I setup a few mild hills in front of the vehicles, and they drive straight through the mesh, no collision at all, the only collision they find is the flat collision. so yeah. first impression, U5 physics is ****ed. bummer. I was so excited about a new physx too.. at least its free! lol
     
  5. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,789

    Thanks James. I forwarded the thread to the client who was hoping the U5 build would work as it made the scenes much more vibrant...but buggy is buggy.
     
  6. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    Code used in test.

    Code (csharp):
    1.  
    2.     void FixedUpdate () {
    3.         if (CurrentAcceleration > 0)
    4.         {
    5.             if (CurrentRPM < MaxRPM)
    6.                 CurrentRPM += Torque * Time.deltaTime;
    7.         }
    8.         else CurrentRPM -= MaxRPM * Time.deltaTime;
    9.  
    10.         CurrentRPM = Mathf.Clamp(CurrentRPM, 0, MaxRPM);
    11.  
    12.         SetRPM();
    13.  
    14.         Vector3 targetVelocity = new Vector3(0, 0, -CurrentRPM / MaxRPM * -Time.deltaTime * 2);
    15.         targetVelocity = transform.TransformDirection(targetVelocity);
    16.  
    17.         Vector3 targetRotation = new Vector3(0, CurrentTurn * Time.deltaTime, 0);
    18.  
    19.         _rigidbody.MovePosition(_rigidbody.position + targetVelocity);
    20.         _rigidbody.MoveRotation(_rigidbody.rotation * Quaternion.AngleAxis(CurrentTurn * Time.deltaTime, Vector3.up));
    21. }
    22.