Search Unity

Unity Physics Discussion

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

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

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    2,577
    In 0.2.2 MeshCollider.Create never returns locking up Unity and just spinning the cpu on our terrain mesh.. It's a procedural mesh with duplicate vertices, that seems like a likely suspect I would think.
     
  2. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    2,577
    So it's hanging in MeshConnectivityBuilder.WeldVertices, although it's not obvious to me at a glance why it would.
     
  3. Rory_Havok

    Rory_Havok

    Joined:
    Jun 25, 2018
    Posts:
    56
    Hi @snacktime, you are right, there is a mistake in the deprecated MeshCollider.Create() - it allocates NativeArrays but doesn't copy the vertices and indices into them (doh!). Will file a bug for that.
    If its hanging in the new (burstable) Create() please send us a dump of the input vertices and indices if posssible so that we can reproduce. Thanks!
     
  4. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    2,577

    Ya so it's not really hanging per say it's just the approach doesn't scale well. 190k verts that's 18 billion iterations in that inner loop, minimum 54 billion array indexes there.
     
    Rory_Havok likes this.
  5. Azzara777

    Azzara777

    Joined:
    Mar 10, 2013
    Posts:
    7
    How do you disable gravity? I set it to 0 in the project settings but it's still on.
     
  6. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    6,949
    You need to be more specific. Which demo you refer to?
     
  7. Rory_Havok

    Rory_Havok

    Joined:
    Jun 25, 2018
    Posts:
    56
    Unity.Physics doesn't use anything from the project settings - those are specific to PhysX.

    Gravity in Unity.Physics defaults to (0,-9.81,0) unless there is a PhysicsStep component found on any entity. That component defines gravity and other simulation settings. For example if you look at the "Hello World" physics sample you will see a "Physics Settings" node in the scene with that component present.
     
  8. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    857
    Well you picked a good weekend to release 0.2.2! Originally I was planning on doing another weekend jam, but the theme/rules ended up being too anti-DOTS_3D for me to be able to finish the only viable option I could think of. So I get to investigate the new updates instead! :D

    First, what hasn't changed which still needs improvement at some point (no surprises here really):
    • Stacking is not a thing yet.
    • Working directly with colliders still requires unsafe API in many cases.
    Side Note: The issue with static colliders invoking the transform system was fixed in the transform system.

    Performance:
    Performance was all over the place but generally better.

    The pool demo got really fast again. After the first couple frames, the spikes stayed under 250 ms compared to 1200 ms I saw earlier. I'm not really sure why that is. Too lazy to find out.

    The asteroid demo with the asteroid count bumped an order of magnitude still has the slightly slower broadphase that I saw in 0.2.0. However, the total simulation job time is way shorter in this version. While the simulation still peaked to 430 ms, it stabilized at 200 ms which wasn't the case in 0.2.0. The big bottleneck now is actually the single-threaded jobs which take nearly half the simulation time.

    Features and API:
    Burst collider generation is awesome. Otherwise there are a few other minor improvements. Nothing I didn't like.

    Internals:
    As I have mentioned before on this forum, I am writing my own physics solution heavily based on Unity.Physics but with different tradeoffs specific to the kinds of games I tend to make. However, I want to keep the low-level math and precision characteristics as similar to Unity.Physics as possible. So thanks to Unity Companion License, I've been deep-diving into the internals of the last missing piece in discrete collision detection which lives in ConvexConvexDistance.cs and ConvexHullBuilder.cs. I'm apparently an idiot because I still can't figure out what the point-simplex solver is doing in terms of machine unit precision compared to Johnson or signed-volume methods. But I definitely noticed the major changes to EPA which seems to be much more robust and also more readable code-wise. That's pretty awesome!

    Overall:
    I like this release. It isn't a huge update, but it also isn't versioned as such.
     
  9. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    2,577
    Here is a quick and dirty implementation with complexity that scales far better. From I had to kill unity after 5+ minutes down to 300ms.

    https://gist.github.com/gamemachine/acfa5d22c770daaaed039d9efe9db23f
     
    Rory_Havok likes this.
  10. WAYN_Group

    WAYN_Group

    Joined:
    Mar 16, 2019
    Posts:
    122
    Hello,

    I updated my project to the latest of every package and faced the following issue:

    When using Physics preview - 0.2.2 with Entites preview - 0.1.1.
    Objects having a PhisicShape authoring component converted to entities through the conversion workflow trigger an error when inspected in the entity debugger and crashes the simulation loop.

    Errro message :
    InvalidCastException: Specified cast is not valid.
    Unity.Properties.Reflection.ReflectedMemberProperty`2[TContainer,TValue].GetValue (TContainer& container) (at Library/PackageCache/com.unity.properties@0.6.2-preview/Runtime/Unity.Properties/Reflection/Properties/ReflectedMemberProperty.cs:24)
    Unity.Properties.PropertyVisitor.VisitProperty[TProperty,TContainer,TValue] (TProperty property, TContainer& container, Unity.Properties.ChangeTracker& changeTracker) (at Library/PackageCache/com.unity.properties@0.6.2-preview/Runtime/Unity.Properties/PropertyVisitor.cs:54)
    Unity.Properties.Reflection.ReflectedPropertyBag`1+PropertyProxy`2[TContainer,TProperty,TValue].Accept[TVisitor] (TContainer& container, TVisitor visitor, Unity.Properties.ChangeTracker& changeTracker) (at Library/PackageCache/com.unity.properties@0.6.2-preview/Runtime/Unity.Properties/Reflection/ReflectedPropertyBag.cs:19)
    Unity.Properties.Reflection.ReflectedPropertyBag`1[TContainer].Accept[TVisitor] (TContainer& container, TVisitor visitor, Unity.Properties.ChangeTracker& changeTracker) (at Library/PackageCache/com.unity.properties@0.6.2-preview/Runtime/Unity.Properties/Reflection/ReflectedPropertyBag.cs:58)
    Unity.Properties.PropertyContainer.Visit[TContainer,TVisitor] (TContainer& container, TVisitor visitor, Unity.Properties.ChangeTracker& changeTracker) (at Library/PackageCache/com.unity.properties@0.6.2-preview/Runtime/Unity.Properties/PropertyContainerVisit.cs:29)
    Unity.Properties.PropertyVisitor.TryVisitContainerWithAdapters[TProperty,TContainer,TValue] (TProperty property, TContainer& container, TValue& value, Unity.Properties.ChangeTracker& changeTracker) (at Library/PackageCache/com.unity.properties@0.6.2-preview/Runtime/Unity.Properties/PropertyVisitor.cs:127)
    Unity.Properties.PropertyVisitor.VisitProperty[TProperty,TContainer,TValue] (TProperty property, TContainer& container, Unity.Properties.ChangeTracker& changeTracker) (at Library/PackageCache/com.unity.properties@0.6.2-preview/Runtime/Unity.Properties/PropertyVisitor.cs:57)
    Unity.Properties.Reflection.ReflectedPropertyBag`1+PropertyProxy`2[TContainer,TProperty,TValue].Accept[TVisitor] (TContainer& container, TVisitor visitor, Unity.Properties.ChangeTracker& changeTracker) (at Library/PackageCache/com.unity.properties@0.6.2-preview/Runtime/Unity.Properties/Reflection/ReflectedPropertyBag.cs:19)
    Unity.Properties.Reflection.ReflectedPropertyBag`1[TContainer].Accept[TVisitor] (TContainer& container, TVisitor visitor, Unity.Properties.ChangeTracker& changeTracker) (at Library/PackageCache/com.unity.properties@0.6.2-preview/Runtime/Unity.Properties/Reflection/ReflectedPropertyBag.cs:58)
    Unity.Properties.PropertyContainer.Visit[TContainer,TVisitor] (TContainer& container, TVisitor visitor, Unity.Properties.ChangeTracker& changeTracker) (at Library/PackageCache/com.unity.properties@0.6.2-preview/Runtime/Unity.Properties/PropertyContainerVisit.cs:29)
    Unity.Properties.PropertyVisitor.TryVisitContainerWithAdapters[TProperty,TContainer,TValue] (TProperty property, TContainer& container, TValue& value, Unity.Properties.ChangeTracker& changeTracker) (at Library/PackageCache/com.unity.properties@0.6.2-preview/Runtime/Unity.Properties/PropertyVisitor.cs:127)
    Unity.Properties.PropertyVisitor.VisitProperty[TProperty,TContainer,TValue] (TProperty property, TContainer& container, Unity.Properties.ChangeTracker& changeTracker) (at Library/PackageCache/com.unity.properties@0.6.2-preview/Runtime/Unity.Properties/PropertyVisitor.cs:57)
    Unity.Properties.Reflection.ReflectedPropertyBag`1+PropertyProxy`2[TContainer,TProperty,TValue].Accept[TVisitor] (TContainer& container, TVisitor visitor, Unity.Properties.ChangeTracker& changeTracker) (at Library/PackageCache/com.unity.properties@0.6.2-preview/Runtime/Unity.Properties/Reflection/ReflectedPropertyBag.cs:19)
    Unity.Properties.Reflection.ReflectedPropertyBag`1[TContainer].Accept[TVisitor] (TContainer& container, TVisitor visitor, Unity.Properties.ChangeTracker& changeTracker) (at Library/PackageCache/com.unity.properties@0.6.2-preview/Runtime/Unity.Properties/Reflection/ReflectedPropertyBag.cs:58)
    Unity.Properties.PropertyContainer.Visit[TContainer,TVisitor] (TContainer& container, TVisitor visitor, Unity.Properties.ChangeTracker& changeTracker) (at Library/PackageCache/com.unity.properties@0.6.2-preview/Runtime/Unity.Properties/PropertyContainerVisit.cs:29)
    Unity.Properties.PropertyVisitor.TryVisitContainerWithAdapters[TProperty,TContainer,TValue] (TProperty property, TContainer& container, TValue& value, Unity.Properties.ChangeTracker& changeTracker) (at Library/PackageCache/com.unity.properties@0.6.2-preview/Runtime/Unity.Properties/PropertyVisitor.cs:127)
    Unity.Properties.PropertyVisitor.VisitProperty[TProperty,TContainer,TValue] (TProperty property, TContainer& container, Unity.Properties.ChangeTracker& changeTracker) (at Library/PackageCache/com.unity.properties@0.6.2-preview/Runtime/Unity.Properties/PropertyVisitor.cs:57)
    Unity.Properties.VisitCollectionElementCallback`1[TContainer].VisitProperty[TElementProperty,TElement] (TElementProperty property, TContainer& container, Unity.Properties.ChangeTracker& changeTracker) (at Library/PackageCache/com.unity.properties@0.6.2-preview/Runtime/Unity.Properties/PropertyVisitor.cs:17)
    Unity.Entities.EntityContainerPropertyBag+ComponentsProperty+GetComponentDataCallback`1[TCallback].Invoke[TComponent] () (at Library/PackageCache/com.unity.entities@0.1.1-preview/Unity.Entities.Properties/EntityContainer.cs:65)
    Unity.Properties.PropertyBag`1[TContainer].Cast[TCallback] (TCallback& callback) (at Library/PackageCache/com.unity.properties@0.6.2-preview/Runtime/Unity.Properties/IPropertyBag.cs:38)
    Unity.Entities.EntityContainerPropertyBag+ComponentsProperty.GetPropertyAtIndex[TGetter] (Unity.Entities.EntityContainer& container, System.Int32 index, Unity.Properties.ChangeTracker& changeTracker, TGetter getter) (at Library/PackageCache/com.unity.entities@0.1.1-preview/Unity.Entities.Properties/EntityContainer.cs:227)
    Unity.Properties.PropertyVisitor.TryVisitCollectionWithAdapters[TProperty,TContainer,TValue] (TProperty property, TContainer& container, TValue& value, Unity.Properties.ChangeTracker& changeTracker) (at Library/PackageCache/com.unity.properties@0.6.2-preview/Runtime/Unity.Properties/PropertyVisitor.cs:159)
    Unity.Properties.PropertyVisitor.VisitCollectionProperty[TProperty,TContainer,TValue] (TProperty property, TContainer& container, Unity.Properties.ChangeTracker& changeTracker) (at Library/PackageCache/com.unity.properties@0.6.2-preview/Runtime/Unity.Properties/PropertyVisitor.cs:87)
    Unity.Entities.EntityContainerPropertyBag.Accept[TVisitor] (Unity.Entities.EntityContainer& container, TVisitor visitor, Unity.Properties.ChangeTracker& changeTracker) (at Library/PackageCache/com.unity.entities@0.1.1-preview/Unity.Entities.Properties/EntityContainer.cs:265)
    Unity.Properties.PropertyContainer.Visit[TContainer,TVisitor] (TContainer& container, TVisitor visitor, Unity.Properties.ChangeTracker& changeTracker) (at Library/PackageCache/com.unity.properties@0.6.2-preview/Runtime/Unity.Properties/PropertyContainerVisit.cs:29)
    Unity.Properties.PropertyContainer.Visit[TContainer,TVisitor] (TContainer& container, TVisitor visitor, Unity.Properties.IVersionStorage versionStorage) (at Library/PackageCache/com.unity.properties@0.6.2-preview/Runtime/Unity.Properties/PropertyContainerVisit.cs:15)
    Unity.Entities.Editor.EntitySelectionProxyEditor.OnInspectorGUI () (at Library/PackageCache/com.unity.entities@0.1.1-preview/Unity.Entities.Editor/EntityInspector/EntitySelectionProxyEditor.cs:44)
    UnityEditor.UIElements.InspectorElement+<CreateIMGUIInspectorFromEditor>c__AnonStorey1.<>m__0 () (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorElement.cs:501)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)

    Reverting to Entites preview - 0.1.0 fix the issue.

    Seem to be linked to the jump from "com.unity.properties" 0.5.0-preview to 0.6.2-preview.
     
  11. WAYN_Group

    WAYN_Group

    Joined:
    Mar 16, 2019
    Posts:
    122
    Hello,

    After updating to Physics preview - 0.2.2, when casting a ray from a job I get the following error :

    InvalidOperationException: The previously scheduled job BoundingVolumeHierarchy:BuildFirstNLevelsJob writes to the NativeArray BuildFirstNLevelsJob.Ranges. You are trying to schedule a new job TargetSelectionSystem:TargetSelectionSystemJob, which reads from the same NativeArray (via TargetSelectionSystemJob.Data.CollisionWorld.Broadphase.m_StaticTree.Ranges). To guarantee safety, you must include BoundingVolumeHierarchy:BuildFirstNLevelsJob as a dependency of the newly scheduled job.
    Unity.Entities.JobForEachExtensions.Schedule (System.Void* fullData, Unity.Collections.NativeArray`1[T] prefilterData, System.Int32 unfilteredLength, System.Int32 innerloopBatchCount, System.Boolean isParallelFor, System.Boolean isFiltered, Unity.Entities.JobForEachExtensions+JobForEachCache& cache, System.Void* deferredCountData, Unity.Jobs.JobHandle dependsOn, Unity.Jobs.LowLevel.Unsafe.ScheduleMode mode) (at Library/PackageCache/com.unity.entities@0.1.0-preview/Unity.Entities/IJobForEach.cs:431)
    Unity.Entities.JobForEachExtensions.ScheduleInternal_CC[T] (T& jobData, Unity.Entities.ComponentSystemBase system, Unity.Entities.EntityQuery query, System.Int32 innerloopBatchCount, Unity.Jobs.JobHandle dependsOn, Unity.Jobs.LowLevel.Unsafe.ScheduleMode mode) (at Library/PackageCache/com.unity.entities@0.1.0-preview/Unity.Entities/IJobForEach.gen.cs:1920)
    Unity.Entities.JobForEachExtensions.Schedule[T] (T jobData, Unity.Entities.ComponentSystemBase system, Unity.Jobs.JobHandle dependsOn) (at Library/PackageCache/com.unity.entities@0.1.0-preview/Unity.Entities/IJobForEach.gen.cs:811)
    TargetSelectionSystem.OnUpdate (Unity.Jobs.JobHandle inputDependencies) (at Assets/Scripts/Server/CombatModule/Systems/TargetSelectionSystem.cs:44)
    Unity.Entities.JobComponentSystem.InternalUpdate () (at Library/PackageCache/com.unity.entities@0.1.0-preview/Unity.Entities/ComponentSystem.cs:964)
    Unity.Entities.ComponentSystemBase.Update () (at Library/PackageCache/com.unity.entities@0.1.0-preview/Unity.Entities/ComponentSystem.cs:315)
    Unity.Entities.ComponentSystemGroup.OnUpdate () (at Library/PackageCache/com.unity.entities@0.1.0-preview/Unity.Entities/ComponentSystemGroup.cs:595)
    UnityEngine.Debug:LogException(Exception)
    Unity.Debug:LogException(Exception) (at Library/PackageCache/com.unity.entities@0.1.0-preview/Unity.Entities/Stubs/Unity/Debug.cs:25)
    Unity.Entities.ComponentSystemGroup:OnUpdate() (at Library/PackageCache/com.unity.entities@0.1.0-preview/Unity.Entities/ComponentSystemGroup.cs:599)
    Unity.Entities.ComponentSystem:InternalUpdate() (at Library/PackageCache/com.unity.entities@0.1.0-preview/Unity.Entities/ComponentSystem.cs:831)
    Unity.Entities.ComponentSystemBase:Update() (at Library/PackageCache/com.unity.entities@0.1.0-preview/Unity.Entities/ComponentSystem.cs:315)
    Unity.Entities.DummyDelegateWrapper:TriggerUpdate() (at Library/PackageCache/com.unity.entities@0.1.0-preview/Unity.Entities/ScriptBehaviourUpdateOrder.cs:144)

    My system is schedule to run after BuildPhysicsWorld
    Code (CSharp):
    1.  
    2.  
    3. [UpdateAfter(typeof(BuildPhysicsWorld))]
    4. public class TargetSelectionSystem : JobComponentSystem
    5. {
    6.  
    7.  
    8.  
    9.     [BurstCompile]
    10.     struct TargetSelectionSystemJob : IJobForEach<Target,PlayerInput>
    11.     {
    12.         [ReadOnly] public CollisionWorld CollisionWorld;
    13.         public void Execute(ref Target target,ref PlayerInput playerInput)
    14.         {
    15.            
    16.  
    17.             RaycastInput input = new RaycastInput()
    18.             {
    19.                 Start = playerInput.cameraPosition,
    20.                 End = playerInput.mouseInput.viewPointRayDirection,
    21.                 Filter = CollisionFilter.Default
    22.             };
    23.             RaycastHit hit;
    24.  
    25.             if (CollisionWorld.CastRay(input, out hit)){
    26.                 target.Entity = CollisionWorld.Bodies[hit.RigidBodyIndex].Entity;
    27.             }
    28.         }
    29.     }
    30.  
    31.     protected override JobHandle OnUpdate(JobHandle inputDependencies)
    32.     {
    33.         var job = new TargetSelectionSystemJob()
    34.         {
    35.             CollisionWorld = World.Active.GetExistingSystem<BuildPhysicsWorld>().PhysicsWorld.CollisionWorld
    36.         };
    37.      
    38.  
    39.         return job.Schedule(this, inputDependencies);
    40.     }
    41. }
    42.  
    Tried scheduling in LateSimulationGroup, same result...

    EDIT :

    Adding World.Active.GetOrCreateSystem<BuildPhysicsWorld>().FinalJobHandle.Complete(); before scheduling the job
    and
    job.Complete() just after scheduling it solve the issue for some reason...
     
    Last edited: Sep 8, 2019
  12. linfuqing

    linfuqing

    Joined:
    May 11, 2015
    Posts:
    69
    Thanks for the answer.
    I have a few more questions about that.
    1.I can't find the fixs in version 0.2.2,will it get fixed in the next version?
    2.Can replace the type of parameter "constraints" of SimplexSolver.Solve to NativeSlice<SurfaceConstraintInfo> that we don't need to create temp NativeArray per chunk?
    3.How can I implement a version with the angular speed of CharacterControllerUtilities.CollideAndIntegrate that can support any collider shape?
     
  13. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    37
    1. Unfortunately it didn't make it for this release, but it will be available in the next one.
    2. We need to have a storage for constraints living somewhere, so allocation needs to happen. We could change the interface of the inner methods (like SimplexSolver.Solve) to use NativeSlice, but in the end at the top level it needs to point to some memory (NativeArray). It could be that I misunderstood your question completely, so please tell me if this doesn't make much sense.
    3. It is going to be tricky, since the solver doesn't support angular effects. Solving angular velocities is not nearly as trivial as solving linear velocities (check regular Solver.cs) and would require a new and more complex solver. Other parts (collide and integrate) should be fairly easy, you would just add angular integration and sub integration wherever there is linear movement. But the solver part is probably going to be a deal breaker. May I ask why you need this? Does your character need angular movement other than turning around vertical axis?
     
  14. jacquesalbert

    jacquesalbert

    Joined:
    Jul 9, 2019
    Posts:
    10
    Has anyone determined a good way to use CalculateDistance (or OverlapAabb) to return a list of all hits inside a job? Seems NativeList and Jobs don't agree with each other so I am trying to figure out how to parallelize that part.

    Edit: For anyone else who runs into it, I don't know what the simplest answer is to get a list of hits OUT of a job, but in my case I realized I just needed to use them IN the job, so declaring the list inside the job would do. That works just fine.
     
    Last edited: Sep 12, 2019
  15. linfuqing

    linfuqing

    Joined:
    May 11, 2015
    Posts:
    69
    1.SimplexSolver.Solve2d maybe has the same issue?
    upload_2019-9-10_14-7-31.png
     
  16. linfuqing

    linfuqing

    Joined:
    May 11, 2015
    Posts:
    69
    2.Sorry my English is poor.
    In CharacterControllerBehaviour.cs:
    Code (CSharp):
    1.  
    2.             // Maximum number of hits character controller can store in world queries
    3.             const int maxQueryHits = 128;
    4.             var distanceHits = new NativeArray<DistanceHit>(maxQueryHits, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
    5.             var castHits = new NativeArray<ColliderCastHit>(maxQueryHits, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
    6.             var constraints = new NativeArray<SurfaceConstraintInfo>(4 * maxQueryHits, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
    7.  
    I have a lot of chunks that alloc in job maybe not good for me.
    I want to replace it to:
    Code (CSharp):
    1.  
    2.             int startIndex = chunkIndex << queryHitShilft, length = 1 << queryHitShilft;
    3.             var distanceHits = this.distanceHits.Slice(startIndex, length);
    4.             var castHits = this.castHits.Slice(startIndex, length);
    5.             var constraints = this.constraints.Slice(startIndex << 2, length << 2);
    6.  
    And alloc the array in main thread.
    3.Some time my character is a animal,like this:
    upload_2019-9-10_14-46-14.png
    It's collider is a box:
    upload_2019-9-10_14-47-5.png upload_2019-9-10_15-16-30.png
    And I need it stand in terrain surface:

    Most of time it work well.
    But some time it tunnel through the terrain when turning.
    I think it's due to the CollideAndIntegrate can not support angular well.Is there any other solution?
     
    Last edited: Sep 10, 2019
  17. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    239
    We don't really support asymmetric character shapes at the minute. Can a sphere be used for the collider?
     
  18. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    239
  19. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    1,346
    @steveeHavok I'm heading that way. I'd love to attend your (?) Havok session but I may need to leave that one bit early as I gotta run for beta event right after it. I wish the schedules weren't this tight (missing lots of interesting DOTS talks now) but it is what it is :)
     
    steveeHavok likes this.
  20. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    37
    I'll try to reply to all 3 questions here.
    1. Yes, I realized it's a more general issue. If you look at these planes, you'll see that they are almost completely (but not entirely) opposing. Then your free axis is almost perfectly vertical, and in order to solve these constraints, you need a really high velocity to get out of that "squeezing" situation. I think we need to apply a more general fix up, even the previous fix didn't actually solve this problem, only reduced it. I'm thinking about introducing a maximum character velocity and clamping whatever comes out from the solver to that value. Thoughts? You can try that on your own and let me know how it works.
    2. I've started an internal discussion about this. We might be able to do something about it. Just to ask - how many characters do you have in your scene? Since this allocation is per chunk, and from what I've seen a chunk can contain quite a lot of characters, you should still have only one allocation if you have few characters (say less than 30).
    3. Yeah, unfortunately we haven't designed for asymmetric characters as @steveeHavok already mentioned. You can try to work around this if you are sure your tunneling issues are coming from turning. When wanting to turn, you can do a query (say CalculateDistance) and make sure new rotation isn't causing new penetrations. If it is, simply create a constraint for it and add it to the list. Or solve it separately using a simplex solver. Do you think this would work?
     
  21. astropuffin

    astropuffin

    Joined:
    May 16, 2015
    Posts:
    7
    I'm running into an issue with physics steps in my unit tests. My code works just fine running in the editor, but not during unit tests and I'm not sure why. Here's a standalone unit test I wrote to check that physics is both triggering AND updating the position of an entity.

    Code (CSharp):
    1. using System.Collections;
    2. using NUnit.Framework;
    3. using Unity.Entities;
    4. using Unity.Entities.Tests;
    5. using Unity.Mathematics;
    6. using Unity.Physics;
    7. using Unity.Physics.Extensions;
    8. using Unity.Physics.Systems;
    9. using Unity.Transforms;
    10. using UnityEngine.TestTools;
    11. using SphereCollider = Unity.Physics.SphereCollider;
    12.  
    13. namespace Tests.UnityScripts {
    14.     public class MotionTest :ECSTestsFixture {
    15.  
    16.         [UnityTest]
    17.         public IEnumerator ShouldUpdateTranslationOnPhysicsUpdate() {
    18.             var e = m_Manager.CreateEntity();
    19.             // Translation
    20.             m_Manager.AddComponentData(e, new Translation{Value = new float3(0,0,0)});
    21.             // Rotation
    22.             m_Manager.AddComponentData(e, new Rotation{Value = quaternion.identity});
    23.             // Collider
    24.             var spCollider = SphereCollider.Create(float3.zero, 1f);
    25.             m_Manager.AddComponentData(e, new PhysicsCollider {Value = spCollider});
    26.             // Add a non-zero linear Velocity
    27.             m_Manager.AddComponent<PhysicsVelocity>(e);
    28.             m_Manager.SetComponentData(e, new PhysicsVelocity{Angular = float3.zero, Linear = new float3(1,1,1)});
    29.             // Mass
    30.             m_Manager.AddComponent<PhysicsMass>(e);
    31.             m_Manager.SetComponentData(e, PhysicsMass.CreateDynamic(MassProperties.UnitSphere, 1f));
    32.  
    33.             var simulation = new Simulation();
    34.             var stepInput = new SimulationStepInput {
    35.                 World = World.Active.GetOrCreateSystem<BuildPhysicsWorld>().PhysicsWorld,
    36.                 TimeStep = 1000f,
    37.                 ThreadCountHint = PhysicsStep.Default.ThreadCountHint,
    38.                 NumSolverIterations = PhysicsStep.Default.SolverIterationCount,
    39.                 Gravity = 10f,
    40.                 SynchronizeCollisionWorld = true
    41.             };
    42.             simulation.Step(stepInput);
    43.  
    44.             Assert.AreNotEqual(float3.zero, e.GetPosition());
    45.             simulation.Dispose();
    46.             yield break;
    47.         }
    48.     }
    49. }
    By attaching the debugger I was able to confirm that the physics update step is indeed being run, and it detects my dynamic body for physics. However, the position isn't changing. I see the same behavior with this simulation code and running Update() directly on the active BuildPhysicsWorld. I feel like I'm misunderstanding something fundamental about how physics updates the component values after calculation.
     
  22. Rory_Havok

    Rory_Havok

    Joined:
    Jun 25, 2018
    Posts:
    56
    Hello @astropuffin,

    In a normal simulation step there are 3 ECS systems for physics:
    * BuildPhysicsWorld - builds the physics world from the entity world.
    * StepPhysicsWorld - steps the physics world. Does nothing to the entity world.
    * ExportPhysicsWorld - writes the new transforms and velocities back to the entity world.

    Your test is missing the last step.

    (It is totally fine to use PhysicsWorld and Simulation directly without using ECS, but in that case you need to populate the world and do something with the simulation results yourself.)

    Also FYI, Gravity is a float3 so you are setting (10,10,10) here, and time step of 1000 seconds is massive :)
     
    florianhanke likes this.
  23. hardcodednumber

    hardcodednumber

    Joined:
    May 26, 2014
    Posts:
    52
    I just updated my project from v0.2.0 -> v0.2.2. And I've noticed pressing the play button takes a lot longer to load around ~10-15 seconds (Mississippi style). I also tried doing the same for the UnityPhysicsSamples, and see similar results. Any ideas?
     
    macagu likes this.
  24. astropuffin

    astropuffin

    Joined:
    May 16, 2015
    Posts:
    7
    Thanks for the help, and that makes sense that I'm missing a system somehow. When I attach a debugger, my code is running the ExportPhysicsSystem OnUpdate method. I tried adding the following just in case, but I still don't have updated entities.

    Code (CSharp):
    1. var exportPhysicsWorld = World.GetOrCreateSystem<ExportPhysicsWorld>();
    2. exportPhysicsWorld.Update();
    The issue seems to be that the ExportPhysicsWorld has an empty PhysicsWorld, but I can't seem to figure out how to tell it to use the right one. Maybe a job dependency? I'll keep searching there, but if you happen to have some code off the top of your head that's in the right direction (even if it's not 100% correct) that would be nice. :)

    My goal is to use pure ECS, even though the hybrid approach might be a little easier right now. ;)
     
    macagu likes this.
  25. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    1,346
    I've noticed a lot longer delay on my project too but didn't connect it to physics package upgrade.
     
  26. Rory_Havok

    Rory_Havok

    Joined:
    Jun 25, 2018
    Posts:
    56
    @hardcodednumber, @rizu - the delay when pressing play is due to the synchronous Burst compile of the collider creation jobs. These are marked synchronous so that the conversion pipeline uses the Bursted versions for much faster collider builds. When the editor caches Burst compiled functions, instead of building everything every time you play, then this should disappear (IIRC that is coming soon in the Burst package, or maybe in newer editor versions).

    @astropuffin - try manually update()'ing the BuildPhysicsWorld system after you have added your components. As I said, all 3 systems must run if you things to be automatic, otherwise you must manually populate the physics world.
     
    thelebaron and rz_0lento like this.
  27. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    6,949
    @Rory_Havok, I have just noticed now, you are M$ employee. That is some new change? Does Havok physics engine were purchased by M$ as well? Will that affect pricing plan, for Havok physics in Unity? If so, does that will affect positively by any chance?
     
  28. Rory_Havok

    Rory_Havok

    Joined:
    Jun 25, 2018
    Posts:
    56
    Havok has been owned by Microsoft since 2015. Nothing new. I'm just trying using this badge in my profile, not sure if I like it or not TBH :)
     
    Antypodish likes this.
  29. konsic

    konsic

    Joined:
    Oct 19, 2015
    Posts:
    979
    Is Havok having the same performance as Physx 4.1?
     
  30. WAYN_Group

    WAYN_Group

    Joined:
    Mar 16, 2019
    Posts:
    122
    Found a way to solve the issue "InvalidOperationException: The previously scheduled job BoundingVolumeHierarchy:BuildFirstNLevelsJob writes to the NativeArray" without relying on the complete() method :

    Code (CSharp):
    1.         var job = new SomeJob().Schedule(this, JobHandle.CombineDependencies(inputDependencies, World.Active.GetOrCreateSystem<BuildPhysicsWorld>().FinalJobHandle));
    2.  
    3.  
    4.         job = JobHandle.CombineDependencies(job, World.Active.GetOrCreateSystem<BuildPhysicsWorld>().FinalJobHandle);
    5.         m_EntityCommandBufferSystem.AddJobHandleForProducer(job);
    6.  
    7.         return job;
    8.     }
    9.  
     
  31. hardcodednumber

    hardcodednumber

    Joined:
    May 26, 2014
    Posts:
    52
    @Rory_Havok And the more you know (TM). Thanks for the info.
     
  32. astropuffin

    astropuffin

    Joined:
    May 16, 2015
    Posts:
    7
    Hmm. Yeah that was the first thing I tried before tried the simulation approach and coming here.

    Code (CSharp):
    1. using System.Collections;
    2. using NUnit.Framework;
    3. using Unity.Entities.Tests;
    4. using Unity.Mathematics;
    5. using Unity.Physics;
    6. using Unity.Physics.Extensions;
    7. using Unity.Physics.Systems;
    8. using Unity.Transforms;
    9. using UnityEngine.TestTools;
    10. using SphereCollider = Unity.Physics.SphereCollider;
    11.  
    12. namespace Tests.UnityScripts {
    13.     public class MotionTest :ECSTestsFixture {
    14.  
    15.         [UnityTest]
    16.         public IEnumerator ShouldUpdateTranslationOnPhysicsUpdate() {
    17.             var e = m_Manager.CreateEntity();
    18.             // Translation
    19.             m_Manager.AddComponentData(e, new Translation{Value = new float3(0,0,0)});
    20.             // Rotation
    21.             m_Manager.AddComponentData(e, new Rotation{Value = quaternion.identity});
    22.             // Collider
    23.             var spCollider = SphereCollider.Create(float3.zero, 1f);
    24.             m_Manager.AddComponentData(e, new PhysicsCollider {Value = spCollider});
    25.             // Add a non-zero linear Velocity
    26.             m_Manager.AddComponent<PhysicsVelocity>(e);
    27.             m_Manager.SetComponentData(e, new PhysicsVelocity{Angular = float3.zero, Linear = new float3(1,1,1)});
    28.             // Mass
    29.             m_Manager.AddComponent<PhysicsMass>(e);
    30.             m_Manager.SetComponentData(e, PhysicsMass.CreateDynamic(MassProperties.UnitSphere, 1f));
    31.  
    32.             var buildPhysicsWorld = World.GetOrCreateSystem<BuildPhysicsWorld>();
    33.             buildPhysicsWorld.Update();
    34.  
    35.             Assert.AreNotEqual(float3.zero, e.GetPosition());
    36.             yield break;
    37.         }
    38.     }
    39. }
    I'll keep digging :/
     
  33. Secto_Argonia

    Secto_Argonia

    Joined:
    Aug 5, 2019
    Posts:
    1
    I'm trying to put a player through the spawn system, using about the same prefab as in the example of Joint 4b with LimitDOFJoint. The problem is that if you convert the player directly from the Hierarchy, the Joint entity is created, and if through the SpawnJob, then no. I'm a little stuck here. It is unclear why Joint Entity is not created on instance Instantiate in SpawnJob?

    Code (CSharp):
    1.  
    2. struct SpawnJob : IJobForEachWithEntity<PlayerSpawner, LocalToWorld>
    3.     {
    4.         public EntityCommandBuffer CommandBuffer;
    5.        
    6.         public void Execute(Entity entity, int index,
    7.                             [ReadOnly] ref PlayerSpawner spawner,
    8.                             [ReadOnly] ref LocalToWorld location)
    9.         {
    10.            
    11.             var instance = CommandBuffer.Instantiate(spawner.Prefab);
    12.             var position = math.transform(location.Value, new float3(0, 0, 0));
    13.             CommandBuffer.SetComponent(instance, new Translation { Value = position });
    14.             CommandBuffer.DestroyEntity(entity);
    15.         }
    16.     }
    Code (CSharp):
    1. public class PlayerSpawnerProxy : MonoBehaviour, IDeclareReferencedPrefabs, IConvertGameObjectToEntity
    2. {
    3.     public GameObject Prefab;
    4.  
    5.     public void DeclareReferencedPrefabs(List<GameObject> gameObjects)
    6.     {
    7.        gameObjects.Add(Prefab);
    8.     }
    9.  
    10.     public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    11.     {
    12.         var spawnerData = new PlayerSpawner
    13.         {
    14.             Prefab = conversionSystem.GetPrimaryEntity(Prefab)
    15.         };
    16.         dstManager.AddComponentData(entity, spawnerData);
    17.        
    18.     }
    19. }
     

    Attached Files:

  34. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    2,577
    On the terrain colliders, are we supposed to use the scale as an indirect way to control resolution?
     
  35. Rory_Havok

    Rory_Havok

    Joined:
    Jun 25, 2018
    Posts:
    56
    Currently yes, that transforms from the heighmap's integer space to the collider's local space.
    Note the terrain collider is a work in progess, the API may change when we finish it (adding authoring support, multiple material support, holes, etc).
     
  36. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    2,577
    I was referring to the quad sizes.

    In our case we made some higher level design changes just recently that have us moving from custom meshes to the terrain system. So I have a real use case I've been working through converting.

    First thing was partitioning the terrain in some way had to be a thing. We have runtime height updates. Updating the entire collider on a 2k terrain is untenable. Easy enough to solve I just put in grid based partitioning. But the quad resolution is still an issue. Quite a few terrains including ours have large contiguous areas that are the same height.

    But I'm not sure quad resolution is really the best solution now. With partitioning I can control the partition size, and I think just inserting a single quad for partitions where the height is the same might actually be the more flexible overall solution.

    Lots of partitions doesn't really impact load time if done right. Ie bake out the colliders as raw pointer data. Runtime load data directly into a collider pointer and batch instantiate the entities. With that the difference between 1 and several hundred colliders is negligible. If you create them at runtime from height data, it's a very different story.
     
  37. macagu

    macagu

    Joined:
    Sep 30, 2012
    Posts:
    7
    Hi everyone.
    1. Does anyone knows if the last version (0.2.2) is cross-platform deterministic ready?
    2. What would be the best approach to manually advance simulation steps? (analog to Physics.Simulate)

    I'm planning to use this on a multiplayer game. I would like to advance the simulation only when "new frames" have been received, and pause it when there are no frames "available" (like a video stream).

    A "paused" flag on StepPhysicsWorld may do the trick... but i'm having troubles to replicate this system.. it depends on BuildPhysicsWorld, ExportPhysicsWorld...

    I was not able to run the simulation folowing the suggested PhysicsRunner.cs on previous posts.
     
  38. tarahugger

    tarahugger

    Joined:
    Jul 18, 2014
    Posts:
    119
    Upgrading from 0.2.0 to 0.2.2 - spawning entity prefabs that contain a tighly packed hierarchy broke for me (a destruction fracture where fragments explode and go everywhere). It worked fine before and now the fragments go 800-1000 units/s in every direction even when they start with 0 velocities. :S
     
  39. Rory_Havok

    Rory_Havok

    Joined:
    Jun 25, 2018
    Posts:
    56
    Unity.Physics has always been deterministic on any given platform and will continue to be. Whenever Burst becomes cross-platform deterministic, Unity.Physics should just work cross-platform deterministically too.
     
    macagu likes this.
  40. macagu

    macagu

    Joined:
    Sep 30, 2012
    Posts:
    7
    Thanks @Rory_Havok
    By your answer, i infer that Brust (currently at version 1.1.2) is not yet cross-platform deterministic (but it will be on the furure). At this moment its not guaranteed that simulations given a same input can run the exact same results on any platform/device. Is this correct?
     
  41. Rory_Havok

    Rory_Havok

    Joined:
    Jun 25, 2018
    Posts:
    56
    Correct. Nothing in Unity that uses floats can run the exact same results on any platform/device currently.
     
    macagu likes this.
  42. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    239
    Unity Physics 0.2.4-preview released!

    Folks, we released a new package of Unity Physics. The high level bullet points include
    • a bunch of bug fixes (thanks to all you good folk that find and help with these)
    • optimization to make single static compound body for all GameObjects with Physics Shapes but no Body.
    • gravity application moved to start of step rather than after solve.
    • a better set of collision event information
    • a bump in the entity package dependency to 0.1.1-preview
    I recommend checking out the Change Log for the full details. Please, also if you have the UnityPhysicsSamples project from GitHub please grab the latest.

    If anyone is at Unite this weekend, please think of getting along to Adam's talk titled Get moving: An overview of Physics in DOTS. If you get to that talk, hopefully you hang around directly after hear me talk about ...​
     
    Last edited: Sep 23, 2019
  43. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    239
    Havok Physics for DOTS!

    Back at GDC 2019 we announced that we would be making Havok Physics available for the DOTS framework. The concept was that by using the same data description you could choose the simulation backend that best fits your needs.
    SPHPBackEnd.png
    I’m delighted to announce that the Havok Physics backend for DOTS is available now from the package manager.

    HPPackage.png

    The 0.2.4 Unity Physics release is the foundation for this first Havok Physics release!

    This is a free trial preview package for everyone to use until January 15th 2020. We'll release the final package before the trial expires. At that point, Havok Physics will remain free for Personal and Plus users, while Pro users will be able to license the package for $20 per seat per month through the Asset Store.

    PyramidsHORT.gif

    I'm giving a talk at Unite on the core differences between the Unity Physics and Havok Physics simulation backends. The two main areas focus around performance and behaviour. In your average dynamic environment, the Havok Physics simulation will give you around a 2x performance improvement. The more robust solver will also provide stable stacking that some of you have been asking for.

    Really looking forward to hearing all your feedback.
     
    Shinyclef, rileyoc, GliderGuy and 8 others like this.
  44. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    384
    Love seeing this released, one issue I've had is that it seems to be incompatible with hdrp. In both game view and the mini scene view, a camera will stop working correctly with the havok package installed if hdrp is also installed. Havent tried in a build.
    Built-in appears to work, havent tried lwrp/universal. Also if you add hdrp after havok, you will need to restart the project for the bug/resulting effect to appear. I reported this as case 1186138
     
    steveeHavok likes this.
  45. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    2,577
    It's getting a bit frustrating that we keep accumulating modifications to the source around things to do with scale.

    The improvements to weldvertices in 0.2.4. Optimizing a broken approach isn't the solution. I'm still giving the benefit of the doubt that possibly the real fix was maybe not enough time for 0.2.4. Because this one I was kind of at a loss for words when I looked at the changes made.

    Static collilders. broken at any real scale for games that add/remove them at runtime. This one is a bit dumbfounding. Considering you guys promote with demo's like megacity. If megacity was a real game with say being able to destroy structures, Unity.Physics would bring the game to it's knees.
     
    Last edited: Sep 23, 2019
  46. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    384
    Ok just to follow up that report:
    Adding hdrp to havok or havok to hdrp -> restart and camera doesnt work. BUT if you add another package, seemingly any unrelated package, camera works again, until you inevitably restart. Weird bug.
     
    steveeHavok likes this.
  47. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    2,577
    FYI just so you guys don't think I'm generally unhappy, that's not at all the case. It's just we are actually making a game at the scale of megacity.

    And for the most part Unity.Physics has been pretty amazing. Quick overview of the scale we have.

    - Vegetation. This was our first at scale feature. 2k average map has 60k vegetation, everything except for grass being 'alive' and interactable. It gets harvested, it reaches it's end of life and new vegetation grows back (at different locations).

    - Terrain collider. Just put this in but so far it seems to just work.

    - Structures. Precisely because Unity.Physics scales so well in query performance and memory usage, we opted to move to a design where we use smaller building blocks. Each one having a collider as they are part of combat. If they get destroyed, they produce rocks with colliders that go back into the entire resource gathering/crafting/building cycle. The structures themselves are another potentially 5 figures of colliders per map.

    We also took advantage of DOTS to up the scale in a lot of other areas. Harvesting is done via npc's, you can literally deforest an entire map. Forest fires can burn down large areas. Combat is at the hundreds of entities involved at once scale. So what this means for physics is not only a large number of queries on a regular basis, but a large number of colliders being created/destroyed also.

    So ya overall we are really happy. Literally you could not make this game in Unity without DOTS. And it would I think be far more difficult in any other engine. Unity has gone from pretty much nothing at scale works performantly, to I can't think of an engine that does it better. Assuming you don't mind living on the edge. But no game pushing anything doesn't, so not a big deal.
     
    GliderGuy, hippocoder and Antypodish like this.
  48. Nothke

    Nothke

    Joined:
    Dec 2, 2012
    Posts:
    59
    OK, the Havok package is seriously impressive, the stacks are incredibly stable. Had a lot of fun playing around. Here's a little twitter thread of some falling stacks and towers.

    I made a script to procedurally spawn a 4 walled-tower of any size. Just put it on any object in game and assign the materials (must have GPU instancing enabled) and cube mesh. You can use it for benchmarking :) For very tall stacks I recommend increasing solver iteration count.

    Edit: Woops, I forgot to mention blockDimensions.x should be 2x blockDimensions.z, so that the bricks would properly interleave on corners. Corrected it so it's initialized at (2, 1, 1)

    Also, if you want to support me you can buy the demo for 1€ :D Hopefully that's the first game published with Havok physics? :D
     
    Last edited: Sep 24, 2019
  49. Karearea

    Karearea

    Joined:
    Sep 3, 2012
    Posts:
    325
    I've been dabbling with ECS over the past week, and absolutely love the potential- it's incredible what you can do.

    I have a few entites that need to set an impulse on the PhysicsVelocity of a different entity. While the job runs fine, and I've pushed data out to debug to this effect, I simply can't seem to apply any impulses. The physics components all convert correctly, but the item simply falls without any influence from physicsVelocity.ApplyImpulse. Is there anything non-obvious (or obvious!) I'm missing in this stripped-down example?

    Code (CSharp):
    1. using Unity;
    2. using UnityEngine;
    3. using Unity.Burst;
    4. using Unity.Collections;
    5. using Unity.Entities;
    6. using Unity.Jobs;
    7. using Unity.Mathematics;
    8. using Unity.Physics;
    9. using Unity.Physics.Extensions;
    10. using Unity.Physics.Systems;
    11. using Unity.Transforms;
    12. using System;
    13.  
    14. [UpdateAfter(typeof(BuildPhysicsWorld)), UpdateBefore(typeof(StepPhysicsWorld))]
    15. public class RemoteImpulseSystem_IJobForEach : JobComponentSystem
    16. {
    17.     BuildPhysicsWorld buildPhysicsWorld;
    18.  
    19.     protected override void OnCreate()
    20.     {
    21.         buildPhysicsWorld = World.GetOrCreateSystem<BuildPhysicsWorld>();
    22.     }
    23.  
    24.     [BurstCompile]
    25.     struct RemoteImpulseJob : IJobForEachWithEntity<VehicleEntityManagerReference, Parent, LocalToWorld, Translation, Rotation>
    26.     {
    27.         [NativeDisableParallelForRestriction] public ComponentDataFromEntity<PhysicsVelocity> physicsVelocitys;
    28.         [NativeDisableParallelForRestriction] public ComponentDataFromEntity<PhysicsMass> physicsMasses;
    29.  
    30.         public void Execute(Entity entity, int index, [ReadOnly]ref VehicleEntityManagerReference vehicleEntityManagerReference, [ReadOnly]ref Parent parent, [ReadOnly]ref LocalToWorld localToWorld, [ReadOnly]ref Translation translation, [ReadOnly]ref Rotation rotation)
    31.         {
    32.             //Get Entity with physics
    33.             Entity physicsEntity = vehicleEntityManagerReference.vehicleEntityManager;
    34.  
    35.             //Get Components
    36.             var physicsVelocity = physicsVelocitys[physicsEntity];
    37.             var physicsMass = physicsMasses[physicsEntity];
    38.  
    39.             //Example impulses
    40.             Matrix4x4 matrix4x4 = Matrix4x4.identity;
    41.             matrix4x4 = localToWorld.Value;
    42.  
    43.             //Relative to this entity
    44.             float3 forcePoint = matrix4x4.MultiplyPoint3x4(Vector3.zero);
    45.             float3 forceUp = matrix4x4.MultiplyPoint3x4(Vector3.up * 100f);
    46.             float3 forceForward = matrix4x4.MultiplyPoint3x4(Vector3.forward * 400000f);
    47.  
    48.             //Apply impulses
    49.             physicsVelocity.ApplyImpulse(physicsMass, translation, rotation, forceUp, forcePoint);
    50.             physicsVelocity.ApplyImpulse(physicsMass, translation, rotation, forceForward, forcePoint);
    51.         }
    52.     }
    53.  
    54.     protected override JobHandle OnUpdate(JobHandle inputDeps)
    55.     {
    56.         buildPhysicsWorld.FinalJobHandle.Complete();
    57.  
    58.         var job = new RemoteImpulseJob()
    59.         {
    60.             physicsVelocitys = GetComponentDataFromEntity<PhysicsVelocity>(),
    61.             physicsMasses = GetComponentDataFromEntity<PhysicsMass>(),
    62.     };
    63.         return job.Schedule(this, inputDeps);
    64.     }
    65. }
     
  50. Rory_Havok

    Rory_Havok

    Joined:
    Jun 25, 2018
    Posts:
    56
    The problem is that you are running your system in between BuildPhysicsWorld and ExportPhysicsWorld. BuildPhysicsWorld copies the PhysicsVelocity's into the physics world, ExportPhysicsWorld writes it back out. So any user changes to PhysicsVelocity between those systems will be stomped by ExportPhysicsWorld. So you should either run this before BuildPhysicsWorld or after ExportPhysicsWorld.

    If you really want to work directly on the physics world you can do that by working on the PhysicsWorld's MotionVelocity array.
     
    Karearea likes this.
Thread Status:
Not open for further replies.
unityunity