Search Unity

Dots camera

Discussion in 'Cinemachine' started by marvalgames, Nov 16, 2020.

  1. marvalgames

    marvalgames

    Joined:
    Sep 29, 2020
    Posts:
    3
    I am using dots physics so the collider extension doesn't do anything? Work around? Thanks
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    For now, you'll have to make your own collider extension that queries Unity.Physics.

    FYI we are working on a 100% DOTS version of Cinemachine. It's still in early stages, as the DOTS API is evolving, but it's looking very good.
     
  3. Unity_gamer

    Unity_gamer

    Joined:
    Aug 19, 2011
    Posts:
    30
    @Gregoryl Any updates on the Dots version Cinemachine ??
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    None that I can share at this time. It's still a thing.
     
    Anthiese likes this.
  5. ToniSnyder

    ToniSnyder

    Joined:
    Dec 2, 2021
    Posts:
    1
    Hi @Gregoryl! Are there any guides/suggestions to making Cinemachine work with Unity.Physics without stuttering? My process connecting Cinemachine with DOTS is simple: create hybrid object as child of PhysicsBody. CompanionLink'ed GameObject transform updated via CopyTransformToGameObjectSystem. And I make this gameobject as Follow and LookAt targets for CinemachineVirtualCamera. No matter what I change (CinemachineBrain update method, Aim/Body types) camera not moving smooth along with body. Maybe there are some "official" methods for glueing Cinemachine and DOTS for current state of DOTS packages? Thanks in advance!
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    @ToniSnyder If the transforms get updated before LateUpdate then CM will see them if the Brain is set to LateUpdate. In that case, you'll have to do some kind of interpolation to adjust for the clock difference between render deltaTime and the physics fixed time step.

    If you're updating UnityPhysics on the FixedUpdate clock with the brain set to FixedUpdate, then you'll need to synch the the transforms (without interpolation) after doing the physics update and before CMBrain does its FixedUpdate.

    Alternatively, you can put the Brain in ManualUpdate mode and call brain.ManualUpdate after the physics has updated and the transforms have been synched.

    Without more info about your game loop I can't really say why you're getting stuttering.
     
    ToniSnyder likes this.
  7. Spy-Shifty

    Spy-Shifty

    Joined:
    May 5, 2011
    Posts:
    546
    Hi there any solution on this problem?

    I have almost the same setup as @ToniSnyder. Physics runs within DOTS and I use the CopyTransformToGameObjectSystem to sync the gameobject with the DOTS world.
    The Camera follows a Virtual Camera with default settings on it (damp xyz =1)

    But doesn't matter what I setup. The camera is stuttering.

    I've also written a custom sync system to synchronize Gameobjects as well as update the brain.

    I tried to run this in normal update, fixed update,.. no matte what I do it stutters.

    Any help on this?

    Code (CSharp):
    1. [UpdateInGroup(typeof(FixedStepSimulationSystemGroup))]
    2. [UpdateAfter(typeof(EndFramePhysicsSystem))]
    3. [UpdateBefore(typeof(CopyPhysicsVelocityToSmoothing))]
    4. public partial class CinemachineBrainUpdateSystem : SystemBase {
    5.     CopyTransformToGameObjectSystem copyTransformToGameObjectSystem;
    6.     private EntityQuery m_TransformGroup;
    7.  
    8.     protected override void OnCreate() {
    9.         base.OnCreate();
    10.         copyTransformToGameObjectSystem = World.GetOrCreateSystem<CopyTransformToGameObjectSystem>();
    11.         m_TransformGroup = GetEntityQuery(ComponentType.ReadOnly(typeof(CopyTransformToGameObject)), ComponentType.ReadOnly<LocalToWorld>(), typeof(UnityEngine.Transform));
    12.     }
    13.  
    14.     protected override void OnStartRunning() {
    15.         base.OnStartRunning();
    16.         copyTransformToGameObjectSystem.Enabled = false;
    17.     }
    18.  
    19.     protected override void OnUpdate() {
    20.  
    21.         var transforms = m_TransformGroup.GetTransformAccessArray();
    22.         var copyTransformsJob = new CopyTransforms {
    23.             LocalToWorlds = m_TransformGroup.ToComponentDataArrayAsync<LocalToWorld>(Allocator.TempJob, out var dependency),
    24.         };
    25.  
    26.         copyTransformsJob.Schedule(transforms, dependency).Complete();
    27.  
    28.  
    29.         Entities.WithoutBurst()
    30.             .ForEach((CinemachineBrain brain) => {
    31.                 brain.ManualUpdate();
    32.             }).Run();
    33.     }
    34.  
    35.  
    36.     [BurstCompile]
    37.     struct CopyTransforms : IJobParallelForTransform {
    38.         [DeallocateOnJobCompletion]
    39.         [ReadOnly] public NativeArray<LocalToWorld> LocalToWorlds;
    40.  
    41.         public void Execute(int index, TransformAccess transform) {
    42.             var value = LocalToWorlds[index];
    43.             transform.position = value.Position;
    44.             transform.rotation = new quaternion(value.Value);
    45.         }
    46.     }
    47. }
    48.  
     
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    @Spy-Shifty Stuttering is almost always due to mismatch between the deltaTime used to calculate motion and the deltaTime for the render frame. When a camera is set to track such an object, this stuttering gets magnified - especially if damping is used - because the target will jitter in the frame. If you turn damping to 0, the target will stop jittering in the frame (because the camera will jitter exactly along with it) but you'll see the background jitter if you look at it. For psychological reasons this is less noticeable, but it's still happening. The problem is in the target's motion.

    I can't tell from here where that mismatch is occurring. Possibly it's aliasing between the physics frame time and the render frame time. Your code is not compensating for this with interpolation.