Search Unity

Official Unity Physics Discussion

Discussion in 'Physics for ECS' started by smcclelland, Mar 18, 2019.

Thread Status:
Not open for further replies.
  1. Shinyclef

    Shinyclef

    Joined:
    Nov 20, 2013
    Posts:
    505
    In my project I slow down time to 0. The kinematic objects which I move myself stop completely, but the dynamic object governed by unity physics' movement don't actually stop, they move very very slowly. Perhaps there's a bug here?
     
  2. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    992
    Hi @steveeHavok,
    Tried your solution. Although it does not trigger any error, it also seem that trigger event are not read by my detroy on colision job when putting the
    UpdateAfter(typeof(StepPhysicsWorld))
    . But using a
    [UpdateAfter(typeof(EndFramePhysicsSystem))]
    avoid having the error message and make my detroy on colision job work properly.
    No need for other dependancies between my system.
    Thanks.
     
    steveeHavok likes this.
  3. Shinyclef

    Shinyclef

    Joined:
    Nov 20, 2013
    Posts:
    505
    Has anyone figured out how to use custom collectors? There is a built-in collector that provides the 1 closest hit, there is another that provides all hits. Here, I've tried to create my own custom collector that provides 'n' closest hits.

    It seems I cannot get it to work.
    - It keeps returning hits that my filter that should have been filtered out, unless I comment out the first 'else' block in "AddHit".
    - I feel like I'm using "TransformNewHits" correctly, but not 100% sure.
    - AddHit returns a boolean. Seems I should return true if I 'accept' the hit. What about my case here where I want to 'replace' an existing hit if this hit is closer? In this case I would 'discard' the previously accepted hit. Is this what's perhaps causing problems?

    Bottom line: How do you create a Collector that provides 'n' nearest collisions?
    Here is what I've tried.

    Code (CSharp):
    1.     public struct ClosestHitsCollector<T> : ICollector<T> where T : struct, IQueryResult
    2.     {
    3.         public NativeList<T> ClosestHits;
    4.  
    5.         public bool EarlyOutOnFirstHit => false;
    6.  
    7.         public float MaxFraction { get; private set; }
    8.  
    9.         public int NumHits => ClosestHits.Length;
    10.  
    11.         public ClosestHitsCollector(float maxFraction, NativeList<T> closestHits)
    12.         {
    13.             MaxFraction = maxFraction;
    14.             ClosestHits = closestHits;
    15.         }
    16.  
    17.         #region ICollector
    18.  
    19.         public bool AddHit(T hit)
    20.         {
    21.             Assert.IsTrue(hit.Fraction <= MaxFraction);
    22.             if (NumHits < ClosestHits.Capacity)
    23.             {
    24.                 MaxFraction = math.max(MaxFraction, hit.Fraction);
    25.                 ClosestHits.Add(hit);
    26.             }
    27.             else // if I comment out this whole else block, at least the filter is respected. Why isn't it respected if I leave it in?
    28.             {
    29.                 // replace existing furthest hit
    30.                 int furthestIndex = 0;
    31.                 float furthest = ClosestHits[0].Fraction;
    32.                 MaxFraction = 0;
    33.                 for (int i = 1; i < NumHits; i++)
    34.                 {
    35.                     float frac = ClosestHits[i].Fraction;
    36.                     if (frac > MaxFraction)
    37.                     {
    38.                         if (frac > furthest)
    39.                         {
    40.                             MaxFraction = furthest;
    41.                             furthest = frac;
    42.                             furthestIndex = i;
    43.                         }
    44.                         else
    45.                         {
    46.                             MaxFraction = frac;
    47.                         }
    48.                     }
    49.                 }
    50.  
    51.                 ClosestHits.RemoveAtSwapBack(furthestIndex);
    52.                 ClosestHits.Add(hit);
    53.                 MaxFraction = math.max(hit.Fraction, MaxFraction);
    54.             }
    55.  
    56.             return true;
    57.         }
    58.  
    59.         public void TransformNewHits(int oldNumHits, float oldFraction, Math.MTransform transform, uint numSubKeyBits, uint subKey)
    60.         {
    61.             for (int i = oldNumHits; i < NumHits; i++)
    62.             {
    63.                 T hit = ClosestHits[i];
    64.                 hit.Transform(transform, numSubKeyBits, subKey);
    65.                 ClosestHits[i] = hit;
    66.             }
    67.         }
    68.  
    69.         public void TransformNewHits(int oldNumHits, float oldFraction, Math.MTransform transform, int rigidBodyIndex)
    70.         {
    71.             for (int i = oldNumHits; i < NumHits; i++)
    72.             {
    73.                 T hit = ClosestHits[i];
    74.                 hit.Transform(transform, rigidBodyIndex);
    75.                 ClosestHits[i] = hit;
    76.             }
    77.         }
    78.  
    79.         #endregion
    80.     }
    And how I called it:
    Code (CSharp):
    1.                 NativeList<DistanceHit> hits = new NativeList<DistanceHit>(5, Allocator.Temp);
    2.                 var collector = new ClosestHitsCollector<DistanceHit>(pointInput.MaxDistance, hits);
    3.                 //var collector = new AllHitsCollector<DistanceHit>(pointInput.MaxDistance, ref hits); // works fine
    4.                 if (CollisionWorld.CalculateDistance(pointInput, ref collector))
    5.                 {
    6.                     for (int i = 0; i < hits.Length; i++)
    7.                     {
    8.                         buf.Add(CollisionWorld.Bodies[hits[i].RigidBodyIndex].Entity);
    9.                     }
    10.                 }
     
  4. fallFlat

    fallFlat

    Joined:
    Mar 26, 2014
    Posts:
    26
    Could it be that physics is running in Update, but using fixedTimeStep as timestep? I've tried changing fixedTimeStep in project settings for example scenes and it influences object velocity.
     
  5. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    Yeah, custom collectors will be made easier. Ultimately AddHit will have all necessary information to filter there and then.
    That said, I don't understand your else clause. If I read that correctly you are always adding a new hit even if its hit fraction is less than anything on the list?
    AddHit should return false if you are not accepting the new hit. If AddHit is false then TransformNewHits will not be called. In TransformNewHits the oldNumHits parameter will be passed the collector.NumHits count from before AddHit is called and it will be irrelevant once you have collected 5 hits and the swaped hit will not get transformed. To correctly transform hits that you replace you should temporarily record the index swapped and only transform that new hit.
     
  6. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    Unrelated to anything but gotta say I love Human: Fall Flat :)
     
  7. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    How are you tweaking time? Do you have a simple repro?
     
  8. Shinyclef

    Shinyclef

    Joined:
    Nov 20, 2013
    Posts:
    505
    Hi there. Suppose I'm collecting 10 closest enemies. I understood that as long as I have MaxFraction be equal to distance/fraction of the 10th furthest enemy, then AddHit won't be called unless it's a hit that I should accept as a replacement for my furthest existing hit, so I should never be retuning false right?

    The else block has 2 jobs.1: identify the existing furthest item for removal. 2: make sure max fraction is equal to the furthest hit of the 10 remaining items. Perhaps I can write this as 2 separate loops to troubleshoot, but even if there is an error, how am I ending up with items that should be filtered until I comment out the else block heh. The filter works perfectly with the all hits collector. I'll have a further play tonight with separate loops to see if I made an error.
     
  9. Shinyclef

    Shinyclef

    Joined:
    Nov 20, 2013
    Posts:
    505
    Time.timeScale. Things are being multiplied by delta time currently due to physics step being in update.

    I guess I should wait until its back in fixed update and then reduce that time scale too... Maybe best not to worry about this for now until things in their final places
     
  10. Vladimir-Borodin

    Vladimir-Borodin

    Joined:
    Jun 1, 2017
    Posts:
    15
    Serialization question.
    For example, I have two cubes, connected with Joint on first one. Both cubes have script, which stores some id.
    So, in old physics i can iterate them, find Joint component, get reference to connected body and have two ids.
    Example of json:
    Code (CSharp):
    1. {
    2.     "cubes": [
    3.         {"id":1},
    4.         {"id":2}
    5.     ],
    6.     "joints" [
    7.         {"from":2, "to":1}
    8.     ]
    9. }
    In the other hand, in new physics I have no any "reference", and joint stores Entity ID. Cubes are for examples, this can be different shapes (cube + sphere etc.)
    Any idea how this can be done with new physics?
     
  11. SamOld

    SamOld

    Joined:
    Aug 17, 2018
    Posts:
    333
    None of what you described is apparent from the current naming. I think that's where people are getting lost. I had no idea what the methods should do when I looked at it. I got a collector working in the end before, but looking back at the interface again now, I'm back to being at a loss for what implementation I should give each method.

    Here's a brief overview of my thought process when looking at it:
    • Which method should actually store the hit? Presumably
      AddHit
      , but what's the return value for? Is it a filter? Do I return false to tell it I'm done and I don't want any more hits?
    • Why are there two
      TransformNewHits
      methods?
    • Do they both run? Can either one run depending on the hit provider?
    • Does
      AddHit
      run before or after
      TransformNewHits
      ?
    • Do the
      TransformNewHits
      methods run for every hit or only once at the end? Plural name suggests it should process multiple hits at once.
    • They don't take a hit parameter and return nothing. What hits exactly should they be transforming? Is it ones I've already stored in my own field structure?
    • What spaces are being transformed between?
    • What's
      oldFraction
      ? Is that fraction like a ray cast distance fraction? What semantically does "old" mean there?
    • What are
      subKey
      and
      numSubKeyBits
      ? I have absolutely no intuitive idea what that means.
    • Does the existence of the transform methods indicate that the hits I'm processing in
      AddHit
      are in some funky space? What if I need the transforms to filter them?
    • If transformation is supposed to use some known provided transform, why isn't it done for me?
    I could work out the answers to these things by digging through the source and examples, but my aim here is to show how confusing it is without doing so. I actually did know the answer a month ago and it's so confusing that I don't remember it at all.

    What's the situation with delegates in Burst and jobs? Would predicate lambdas be a viable API here?
     
    lclemens and thelebaron like this.
  12. Justin_Larrabee

    Justin_Larrabee

    Joined:
    Apr 24, 2018
    Posts:
    106
    I so, so, so cannot wait for a pure ECS version of your controller. I was hoping the new physics would make some things easier to do, but I certainly didn't expect it would help this much!
     
  13. RBogdy

    RBogdy

    Joined:
    Mar 6, 2019
    Posts:
    65
    Is everyone on this thread aware that Unity Physics doesn't work on Android? There have been multiple complaints in other threads without an official point on this.
     
  14. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    What other threads? You sure you are not mixing the regular physics now to "Unity Physics" package?
     
  15. RBogdy

    RBogdy

    Joined:
    Mar 6, 2019
    Posts:
    65
  16. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    789
    The both of the events demo scenes seem to work.
    Unfortunately I don't have the time right now to debug what exactly is going wrong (in fact I wouldn't even know where to begin without taking a day or two to get familiar with the whole physics system).

    I can make a small demo to show the problem though if that would help.
     
    steveeHavok likes this.
  17. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    Make sure you got link.xml on your project so that DOTS packages don't get stripped. I get instant crash in standalone with Unity Physics and missing objects in Hybrid Renderer if I don't have that file there to tell to keep the packages.
     
    steveeHavok likes this.
  18. RBogdy

    RBogdy

    Joined:
    Mar 6, 2019
    Posts:
    65
    Thank you for your suggestion! I tried it but unfortunately I get the same errors in Androidlogcat if I build with burst. When I disable Burst, objects fall trough floor

    Tried on: 2019.1.6f,7f,8f
     
    Last edited: Jun 24, 2019
  19. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,271
    There's a known issue about colliders having the wrong transforms on Android when using subscenes. I'm suspicious this is your issue when Burst is disabled?
     
  20. RBogdy

    RBogdy

    Joined:
    Mar 6, 2019
    Posts:
    65
    I'm not using sub-scenes. I just have a simple scene, with 1 "table" and 1 box (it doesn't really matter how boxes I put on the table). These 2 items have Physics Shape and Physics Body and of course Convert to Entity components.
     
    steveeHavok likes this.
  21. Jawsarn

    Jawsarn

    Joined:
    Jan 12, 2017
    Posts:
    245
    I'm trying to convert my old CharacterController into this new system. Is there any equivalent to the Physics.ComputePenetration that I can use?

    Edited added question: Is the "SurfaceNormal" in queries the normal of the point hit on a collider, or the inverse "ray" from the hit poisition of the collider to the query starting position?
     
    Last edited: Jun 24, 2019
  22. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Are there any known bugs with raycasting reporting false hits on mesh colliders? In the pic below the sphere shows where it's reporting a hit. The ray goes from 1 meter above the red character to one meter above the blue one. The only colliders in the scene are for the ground, which is several mesh colliders. 3 ground meshes do converge in this general area but not exactly where the hit point is.

    It seems to be specific to only certain areas, ie other parts of the map with similar height differences it works fine. Which is why I was thinking that perhaps the convergence of multiple colliders in an area might be part of the issue.

    upload_2019-6-25_22-22-1.png
     
  23. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    I'd enable all possible debug draws from the debug script to possibly see what's going on there.
     
    lclemens, steveeHavok and SamOld like this.
  24. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Ya ok so once I figured out where that debug script was, it showed the problem. I forgot I had a lower resolution mesh being used for collisions.
     
    steveeHavok likes this.
  25. kstothert

    kstothert

    Joined:
    Dec 8, 2016
    Posts:
    68
    I can't get collision world data in a job. error InvalidOperationException: The NativeContainer SightJob.collisionWorld.m_Bodies has been deallocated. All containers must be valid when scheduling a job.
    Code (CSharp):
    1.  [UpdateAfter(typeof(BuildPhysicsWorld)), UpdateBefore(typeof(EndFramePhysicsSystem))]
    2.   public class GetEntitiesInSightSystem : JobComponentSystem {
    3.     BuildPhysicsWorld physicsWorldSystem;
    4.     CollisionWorld collisionWorld;
    5.     EntityQuery ai;
    6.  
    7.     protected override void OnCreate () {
    8.       physicsWorldSystem = World.GetOrCreateSystem<BuildPhysicsWorld>();
    9.       collisionWorld = physicsWorldSystem.PhysicsWorld.CollisionWorld;
    10.  
    11.       ai = GetEntityQuery(
    12.         typeof(AIController)
    13.       );
    14.     }
    15.  
    16.     protected override JobHandle OnUpdate (JobHandle inputDeps) {
    17.       inputDeps = JobHandle.CombineDependencies(inputDeps, physicsWorldSystem.FinalJobHandle);
    18.  
    19.       var job = new SightJob {
    20.         collisionWorld = collisionWorld
    21.       }.Schedule(ai.CalculateLength(), 1, inputDeps);
    22.  
    23.       job.Complete();
    24.       return job;
    25.     }
    26.  
    27.     // [BurstCompile]
    28.     struct SightJob : IJobParallelFor {
    29.       [ReadOnly] public CollisionWorld collisionWorld;
    30.  
    31.       public void Execute (int index) {
    32.         Debug.Log("running sight perception");
    33.       }
    34.     }
    35.   }
     
  26. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    physicsWorldSystem.PhysicsWorld.CollisionWorld can't be cached it must be extracted when you schedule the job.
     
    steveeHavok likes this.
  27. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    Apologies for the delay. Holiday session has a bunch of folk in and out of the office.

    This is all going to change as it is confusing. Originally we assumed that only the supplied collectors would be needed and the current setup is a performance optimization. However, we've all seen how useful and yet confusing, custom collectors are now.

    So AddHit will become the only function and all hit information will be included as need so you can return true to keep the hit, and return false to filter it out.

    Calling CastRay on the world can bring you down the rabbit hole of a collider hierarchy. The current problem is that filtering the hit in a call to AddHit might not possible if you need to filter on the RigidBody index which is only assigned when coming back out of the rabbit hole.

    All queries are ultimately handled in the local space of a leaf collider (e.g. Sphere, Box or Convex). AddHit is called when querying these leaves.
    If a query is performed on a Composite collider (e.g. Mesh, Terrain or Compound) then the code starts digging into child collider hierarchy, until a leaf is found. If AddHit returns true from a leaf then the TransformNewHits function (the one with the subkey) is called as you make your why back up the hierarchy, transforming the hit information from the leaf local space to the parent compound space.
    If a query has been performed on the world or a rigidbody then any hit information is finally transformed again via the other TransformNewHits function (the one with the RB index) to move the hit information from collider space into world space.

    If you have performed queries against a compound collider you need to have some identifier to highlight which child collider was hit. The SubKey is that identifier. For a mesh collider the subkey would identify the individual face. For a compound collider for the subkey would get you the child collider (see CompoundCollider.GetChild).

    TransformNewHits functions are only called after AddHit and only if it returns true.
     
    SamOld likes this.
  28. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    Simple reproduction of problems are always helpful. Thanks.
     
  29. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    We have been seeing issues on Android and working toward fixes with the help of the good folk at Unity. Thanks for continuing to highlight the issues.
     
  30. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    You can call `CalculateDistance()` on a world/rigidbody/collider with `MaxDistance` = 0 to report overlaps. `DistanceHit`contains a `SurfaceNormal` which is the ideal direction to move in to separate the two, and a negative `Distance` which is the amount you would need to move in that direction.
     
    Jawsarn and SamOld like this.
  31. SamOld

    SamOld

    Joined:
    Aug 17, 2018
    Posts:
    333
    Oh. I did a version if this for my character controller but I did something so much more complicated. Now I feel silly. I think we could really do with more intuitive APIs for these things though. What about adding a
    ComputePenetration
    method that just performs that logic you just described? I'll be adding it as an extension method locally.

    Is calling the collider methods (including collider casts) with zero distances recommended? I've been doing it, but it feels like there should be extra overrides for the zero distance cases. I would assume that would allow for extra optimisation in those cases too.
     
  32. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    What is the right abstraction to use for essentially having two collision worlds? I used our static geometry as our first test case, our use case is solely for collision queries. Now I'd like to add some moving objects, again purely to do collision queries against. But our mesh colliders are expensive to rebuild. So I'm guessing I need two collision worlds, or should we do this at a lower level like the BVH itself?f
     
    NotaNaN and SamOld like this.
  33. esc_marcin

    esc_marcin

    Joined:
    Sep 30, 2016
    Posts:
    23
    Looks like Unity Physics does not respect the StaticOptimizeEntity script.

    The ConvertToEntity process correctly adds the Static component and skips adding the Translation & Rotation components in the TransformConversion system, but the Physics system goes ahead and adds them anyways in ConversionExtensions.RemoveParentAndSetWorldTranslationAndRotation. If Physics needs the Transform & Rotation components even for Static objects that's annoying but could be understandable.

    But the EndFrameTRSToLocalToWorldSystem ends up having to take these static objects and update the LocalToWorld matrix from these never changing Translation and Rotation components. That's not okay.
     
  34. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,271
    I pointed this out back when 0.1.0 came out. This is the reply I got. Makes me think that there is some miscommunication between the teams.
    Easy solution would be to add the static component in the exclude group of the entity queries in the transform systems.
    Another easy solution would be for physics to extract the static position and rotation from the ltw using RigidTransform.
     
    MikeMarcin likes this.
  35. SebLazyWizard

    SebLazyWizard

    Joined:
    Jun 15, 2018
    Posts:
    234
    I got an angular velocity as quaternion, how do I convert it to the required float3?
    Code (CSharp):
    1. var angular = math.mul(targetRot, math.inverse(curRot))
    Edit
    Ok I recycled my old solution, but unfortunately I still have to use ToAngleAxis as there is no equivalent in the new math library;
    Code (CSharp):
    1. Quaternion diffRot = math.mul(targetRot, math.inverse(curRot));
    2. diffRot.ToAngleAxis(out var angle, out var axis);
    3. var angular = float.IsInfinity(axis.x) ? float3.zero : math.radians(angle > 180 ? angle - 360 : angle) * math.normalize(axis);
    If anyone knows a solution that only utilizes the new math library then please let me know.
     
    Last edited: Jul 3, 2019
  36. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    I have constant issues with this package. My most recent problem is entities simply falling through a flat ground even though I apply no downward/vertical force.



    In this demo, the only job is this

    Code (CSharp):
    1.  
    2. [BurstCompile]
    3. private struct MoveJob : IJobForEach<PlayerMove, Translation, PhysicsVelocity>
    4. {
    5.     public float3 Target;
    6.  
    7.     public void Execute([ReadOnly] ref PlayerMove player, [ReadOnly] ref Translation translation, ref PhysicsVelocity velocity)
    8.     {
    9.         var v = math.normalizesafe(this.Target - translation.Value).xz * player.Speed;
    10.  
    11.         var l = velocity.Linear;
    12.         l.x = v.x;
    13.         l.z = v.y;
    14.  
    15.         velocity.Linear = l;
    16.     }
    17. }
    where Target is the location of my mouse projected to the ground.

    Where the ground is just a plane

    upload_2019-7-4_12-40-47.png

    The controlled unit is a capsule

    upload_2019-7-4_12-41-4.png

    But I'm pretty sure I know what causes it.

    This does not happen if it's only those 2 entities.
    However as soon as I add one of those yellow cubes that is when the entity starts falling to ground.
    The cube

    upload_2019-7-4_12-41-55.png

    If I miss around with the position, scale, etc of the extra cubes then it starts working as intended but at some point again will randomly start falling through the ground. Very frustrating as I can't really pin down the issue.
     
    Last edited: Jul 4, 2019
  37. DavidSWu

    DavidSWu

    Joined:
    Jun 20, 2016
    Posts:
    183
    Something like this?
    static float3 ToAxis(this quaternion q)
    {
    if(abs(q.value.w) > 1023.75f / 1024.0f)
    return new float3();
    float gain;
    var wSign = q.value.w >= 0 ? 1f : -1f;
    var angle = acos(wSign*q.value.w);
    gain = wSign*2.0f * angle / sin(angle);

    return new float3(q.value.x * gain,q.value.y * gain,q.value.z * gain);

    }
     
    SebLazyWizard likes this.
  38. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    @tertle can you make a project folder so we can reproduce the issue?
     
  39. SebLazyWizard

    SebLazyWizard

    Joined:
    Jun 15, 2018
    Posts:
    234
    Thanks it works, but is there any reason to keep the condition check as it decreases the accuracy of the result?

    Edit
    Ok it is necessary to keep it, but you can increase the accuracy a lot, 1 - the machine epsilon for float is just enough.

    Code (CSharp):
    1.     public static float3 ToAxis(quaternion q)
    2.     {
    3.         if (math.abs(q.value.w) > 1f - 1.192093e-07f)//machine epsilon
    4.             return float3.zero;
    5.         var wSign = q.value.w >= 0 ? 1f : -1f;
    6.         var angle = math.acos(wSign * q.value.w);
    7.         var gain = wSign * 2f * angle / math.sin(angle);
    8.         return new float3(q.value.xyz * gain);
    9.     }
     
    Last edited: Jul 5, 2019
  40. DavidSWu

    DavidSWu

    Joined:
    Jun 20, 2016
    Posts:
    183
    Good edit.
    I agree that you can reduce the epsilon a lot, but I think that we might need slightly more than the machine epsilon as our acos(w) might get dangerously close to 0 and then we are dividing by sin(almost 0). I would use 1- 2*epsilon for good karma.
    Edit: Looking at a Taylor series approximation of acos we shouldn't need more than epsilon, but I won't throw myself into the NAN pit at the mercy of a mobile FPU
     
    Last edited: Jul 5, 2019
  41. Deleted User

    Deleted User

    Guest

    I have the same problem ,do you solve it rightnow?
     
  42. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    789
    Nope, I can't spend even more time on this right now. But I'll try any new versions of the physics package as they get released.
     
  43. Dingoblue

    Dingoblue

    Joined:
    Aug 23, 2018
    Posts:
    2
    The Character Controller example uses PhysicsWorld.CalculateDistance which as part of its input takes a pointer to a collider. This makes the function unsafe and in turn requires us to toggle unsafe code in the player.

    Is that the expectation going forward or is that a limitation of the current API and is that likely to change?
     
  44. DavidSWu

    DavidSWu

    Joined:
    Jun 20, 2016
    Posts:
    183
    Unsafe is good for you, embrace it.
    If you don't like to do things that are unsafe, don't write code.
     
    MostHated likes this.
  45. linfuqing

    linfuqing

    Joined:
    May 11, 2015
    Posts:
    166
    I have the same problem.

    I use the CompoundCollider,but only a sphere collides with terrain mesh.
    upload_2019-7-10_15-15-51.png
    My terrain mesh is closed.
     
    Last edited: Jul 10, 2019
  46. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Make a repro project please. We can't fix this without a repro. Talking about it more won't help... :)
     
  47. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    The problem I'm having is I can't produce a simple repo. It does not appear to be deterministic.
    It appears randomly and disappears randomly, let me give you a few examples of the cases where I've 'fixed' the issue

    1. Scene A unit walks around and falls through floor. I duplicate scene A (ctrl + D in unity), rename it to B and play scene B and in this scene the unit does not fall through floor even though it's identical.

    2. A scenes floor has a physics shape component but the unit is falling through floor. I add mesh collider to the floor and now the floor has both mesh collider and physics shape. The unit no longer falls through floor. I remove the mesh collider (so it's back to it's original state with only the physics shape), unit no longer falls through floor.

    3. I have a custom group for a bunch of systems unrelated to any physics activity (and the movement system is not part of this group.)

    Code (CSharp):
    1. public class VisionGroup : ComponentSystemGroup
    If a unit starts falling through floor. I add

    Code (CSharp):
    1.     [UpdateAfter(typeof(EndFramePhysicsSystem))]
    2.     [UpdateAfter(typeof(TransformSystemGroup))]
    To this group. Now the unit stops falling through floor.

    I then revert the UpdateAfter attributes, and unit still does not fall through the floor. Even though after checking the system update order is identical to the original case where the unit fell through floor.


    For all the above examples, no other change in code, the scene, or anything was changed except what was described. Each of these cases I've been able to experience at least twice.

    I've been trying for days to replicate it reliably without luck, it just appears randomly. The only thing I know is it starts happening after a new collider is added to scene. I only have like 4-6 colliders in scene total, I'm only using Unity.Physics for a few sample scenes not in an actual project at the moment.

    I'm going to attempt the next time I come across the issue, to copy my entire project, see if the issue occurs in the copy and then file the whole project as a bug report (there aren't that many assets.)
     
    Last edited: Jul 10, 2019
  48. linfuqing

    linfuqing

    Joined:
    May 11, 2015
    Posts:
    166
    My project is very large,but i can send you all sources of my game by e-mail if you need?
     
  49. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Wild guess. The building adds an extra body with a null collider, since the broadphase doesn't like building with zero bodies. I think that introduces the chance for an off by one type error the way colliders get set when building. I created a very similar bug on my own when first creating custom worlds.
     
  50. linfuqing

    linfuqing

    Joined:
    May 11, 2015
    Posts:
    166
    Maybe the same issue here.
    1.UnityPhysicsExamples/CharacterController.
    2.Set FixedTime = 0.5
    upload_2019-7-10_17-22-9.png
    3.Move here:
    upload_2019-7-10_17-22-37.png
     
    steveeHavok likes this.
Thread Status:
Not open for further replies.