Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Velocity is different on build, dots physics package

Discussion in 'Physics' started by StivenUnity, Oct 19, 2019.

  1. StivenUnity

    StivenUnity

    Joined:
    Jun 18, 2015
    Posts:
    7
    hello, today I'm testing my game and built my game server.
    my tank not moving! I'm checked linear velocity by debugging logs. tank velocity is so different when i running server at the unity editor.
    I'm using IJobForEach to update PhysicsVelocity. what can I do to get same results like editor?
    velocity.x at editor: 8, velocity.x at windows: 0.0001 for example.
    tested on havok and unity physic engine.
    the code:
    Code (CSharp):
    1.  
    2.         private struct UpdateJob : IJobForEach<PhysicsVelocity, Rotation,
    3.         ServerTankMovementData>
    4.         {
    5.             [ReadOnly]
    6.             public float DeltaTime;
    7.  
    8.             public void Execute(ref PhysicsVelocity physicsVelocity, ref Rotation rotation,
    9.                 [ReadOnly] ref ServerTankMovementData tankMovementData)
    10.             {
    11.                 //move
    12.                 var inputs = new float3
    13.                 {
    14.                     x = tankMovementData.MovementInputs,
    15.                     y = 0,
    16.                     z = -tankMovementData.TurnInputs
    17.                 };
    18.                 physicsVelocity.Linear += inputs * tankMovementData.Speed * DeltaTime;
    19.                 if (!inputs.Equals(float3.zero))
    20.                     rotation.Value = Quaternion.LookRotation(inputs);
    21.             }
    22.         }
    23.  
     
  2. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    When is your UpdateJob being executed? If your UpdateJob is being scheduled between the BuildPhysicsWorld and ExportPhysicsWorld system update then your velocity changes will be overwritten by the simulation itself.

    Also, there is a specific DOTS Physics sub-forum where more eyes could have helped here.
     
  3. StivenUnity

    StivenUnity

    Joined:
    Jun 18, 2015
    Posts:
    7
    thank you, I have fixed this problem by Application.targetFrameRate = 60.