Interpolation some objects causes visual errors

Hi
I have a problem with some objects since i started using smoothing INTERPOLATION on dynamic bodies.

You can see this video for more details

The red ones are meshes with dynamic bodies(made in editor) but the brown ones are dynamic bodies with meshes as children(the dynamic body has no meshes on itself, and it can have 1-4 meshes under it)(all made in code)

Some of them will go crazy and have this ghost effect. It seems to have something to do with the transform matrices somewhere but i can’t find a link or a pattern.

All the debug data seems fine and i can’t understand why some of the brown objects work and some don’t… they all made in same place in the same way

Does ayone know what might be wrong?
Before i enabled interpolation everything worked fine
If i apply another explosion force they will behave the same way again

Thanks

Hi @argibaltzi , could you please clarify that ghost effect a bit more? Do you mean those objects spinning fast in the background?
It might be easier to put fewer objects on the scene so it’s more noticeable. It also depends a lot on video quality.

Did you check your monitor refresh rate and the project vsync setting (under proj settings → quality)?
You could also try drawing colliders in Physics Debug Settings or even printing NormalizedTimeAhead and smoothedTransform in Unity.Physics.GraphicsIntegration.SmoothRigidBodiesGraphicalMotion.SmoothMotionJob (requires making UP package local), to check if the problem lies in physics or rendering .

yes those objects in the back, they seem to appear in 2 or 3 places at the same time in very fast movement.

if you observe the red ones behave normal but on top left part in the back you can see some brown debris going nuts. However once they collide with the ground they snap back to normal behaviour

this happens after i apply the ExplosionForce function

IT ONLY happens when interpolation is activated, no interpolation and its smooth… :smile:

@milos85miki i uploaded a higher res on dropbox (maybe quality is better if u download)

its a bit more clear in the back what happens

I suspect something’s wrong with rotational movement interpolation. Debugging SmoothRigidBodiesGraphicalMotion.SmoothMotionJob should reveal that, I’d say printing out smoothedTransform would be a good start. Also, adding EntityTypeHandle to that job would help identify indexes of problematic entities.
I’d suggest reducing the demo as much as possible, to get something that’s easier to investigate.

i will and see what debug i can achieve, are you saying that there might be a bug in there something or am i doing something wrong?

If you repro the problem when interpolation is ON and there’s no problem when it’s OFF (without touching anything else), I’d say the problem is in interpolation code. Note that it might also be caused by big diffs between rendering and physics FPS, so it’s not necessarily a bug. Imagine you need to interpolate between rotations that differ by 180 degrees on 1 axis, which side would you go (clockwise or counter clockwise)?

I have noticed that high angular explosion velocity usually causes this error, when they dont have much rotation they seem ok (the other flying debris look fine)

the entities that seem to suffer from this are built in code like that

  1. find render meshes that need to explode
  2. cluster them together and build an approximate box collider
  3. create a dynamic body with a box collider and add the render meshes as children

I can’t really see much wrong in my code to be honest, i have compared lots of things in the entity debugger and they all seem to be ok ( i will keep looking )

I will try that debugging you suggested when i find some time and maybe some other tests with no angular velocity

i did some small tests
I set the Angular velocity to zero after i apply an explosion force and the bug is gone…
It seems there is something going wrong with interpolation and high angular velocity

can someone confirm this is indeed a bug in unity physics

It would be great if you could provide exact rotation values that are causing the unexpected behavior. I don’t see any obvious bugs, we’re basically just calling math.nlerp for rotation.

As I already mentioned, if diff between rotations is 180 degrees, it’s quite hard to figure out which way to interpolate. This is just an example, to illustrate that there are hard edge cases for interpolation.

i have seen angular velocities in the range of 300-500, should i apply some caps?

edit: i did some debug logs and i saw some 800 values for angular velocity
is that too high?

its calculated from the ApplyExplosionForce

or is the problem only for previous angular - angular = 180?

Yes, those values sound very high. The example I mentioned is when currentTransform.rotation - prevTransform.rotation = 180 degrees. Of course, those transforms are the results of angular velocity integration for the frame (diff = angVel * dt).

Hi
I was finally able to reproduce this
You need 2 objects

Root
[PhysicsBody with Interpolation on, Mass:1 ]
[PhysicsShape, Size: 0.5, 0.3, 0.2, Center: 3.95, 1.95, 5.5]

Child Mesh (Unity Cube)
LocalScale: 0.5, 0.3, 0.2
LocalPosition: 3.95, 1.95, 5.5

Note: this is not a compound body… its a simple dynamic box collider with a mesh under it
From what i noticed, the smaller the sizes the more strong the ghosting effect it is

This simple explosion will trigger the ghosting if you hit it in the “right place”

 if (Input.GetMouseButtonDown(0))
        {
            Unity.Physics.RaycastHit raycast;
            bool hasIntersection = InputSystem.RaycastWorld(out raycast, CollisionFilter.Default);

            if (hasIntersection)
            {
                float delta = Time.DeltaTime;
                Entities.WithBurst().ForEach((ref PhysicsVelocity velocity, in PhysicsCollider collider, in PhysicsMass mass, in Translation position, in Rotation rotation, in Entity entity) =>
                {
                    velocity.ApplyExplosionForce(
                        mass, collider, position, rotation,
                        500, raycast.Position, 10,
                        delta, new float3(0, 1, 0), CollisionFilter.Default, 0.8f);

                }).Run();
            }
        }

If you disable interpolation then it works fine

Have you tried printing smoothedTransform values in SmoothRigidBodiesGraphicalMotion.SmoothMotionJob?
This really sounds like a problem in interpolation with big angular velocities, I’ll try to repro and take a look…

this only happens when there is an offset on the child
i tried with a 0,0,0 offset and it worked as expected
It seems some combination of child offset and rotation interpolation is making it look like that?

I haven’t tried printing the smoothmotionjobs yet

Would also like to point out that even with my Physics is 60 FPS and Rendering at 60 FPS, i still get this bug when interpolation is on

Thanks for the info, I’ll try to repro locally and investigate.

Hi @argibaltzi , it should be fine if you set the desired scale (0.5, 0.3, 0.2) on Root object and leave PhysicsShape size and child scale at (1,1,1). Is that ok for your use-case?

Regarding my use-case that is not possible

The root physics object has a box collider that is an approximation of all mesh boxes under it. There is usually 1-6 meshes under it and they are sometimes close to 0.0.0 and sometimes far from it

Were you able to find out what is wrong? Is it a limitation or a bug? Its strange it only happens when interpolation is on

SmoothRigidBodiesGraphicalMotion does a regular (and easy) job there, since the parent has no scale. However, seems like something doesn’t fit together well later when child’s LTW is calculated (in EndFrameTRSToLocalToWorldSystem, EndFrameTRSToLocalToParentSystem and/or EndFrameLocalToParentSystem), because child has scale and parent was interpolated.

Will investigate further and let you know when I have some news.

ok i see, so there is something wrong in the system it seems