Search Unity

Resolved Syncronisation issue

Discussion in 'Entity Component System' started by kizko, May 31, 2023.

  1. kizko

    kizko

    Joined:
    May 28, 2020
    Posts:
    14


    Player: Cat car (second part of the video)
    Entity: Orange box

    Hello. I do have a problem when I try to sync my Player's position with the entity position.
    I do capture the Player's position and I write it down in a component. I use monobehaviour and I do update it in FixedUpdate():

    Code (CSharp):
    1.   em.SetComponentData(targetEntityWorld, new PlayerTransformComponent
    2.         {
    3.             position = new float3(_playerTransform.position.x, _playerTransform.position.y, _playerTransform.position.z),
    4.             rotation = _playerTransform.rotation
    5.         });

    In the ECS world, I grab it and transform the entities position using an IEntityJob:

    Code (CSharp):
    1.      distance = playerPositionEntity - localTransform.Position;
    2.             if (math.distancesq(playerPositionEntity, localTransform.Position) > 0.1f)
    3.             {
    4.                 localTransform.Position += new float3(distance.x, distance.y, distance.z);
    5.                 localTransform.Rotation = playerRotationEntity;
    6.             }
    Is there a way to get rid of the jittering? I am not sure where I lose the sync point or am I missing something when assigning the position to the Entity?

    Note: I need the Entity to copy the player's position as close as possible.


    What I tried:
    1. Using deltaTime without multiplier. This fixed the issue and made the entity smooth in its movement but it had a lot of delays from my player's location. Adding multiplayer (* speed) will only make it as before.
    2. Updating the position in Update() instead of FixedUpdate(). Same result.
    3. Adding a min distance to apply the transform (in order to get rid of jittering at (0,0,0)).
    4. Summoning a god to help me. No luck.
    Thank you for your time.
     
  2. TheOtherMonarch

    TheOtherMonarch

    Joined:
    Jul 28, 2012
    Posts:
    866
    It almost looks like some kind of gravity is being applied to the orange box.
     
  3. kizko

    kizko

    Joined:
    May 28, 2020
    Posts:
    14
    *One eternity later*: It was the Physics Body (rigidbody) attached to the entity. That was causing the jittering. It was pushing the object down due to gravity while my script was trying to update the position. Thank you!