Search Unity

lerp and transform direction

Discussion in 'Entity Component System' started by shotoutgames, Aug 11, 2020.

  1. shotoutgames

    shotoutgames

    Joined:
    Dec 29, 2013
    Posts:
    290
    How do I use lerp and/or TransformDirection in a DOTS update?



    Code (CSharp):
    1.      gun.Duration += dt;
    2.                 //if ((gun.Duration > gun.Rate) || (gun.WasFiring == 0))
    3.                 if ((gun.Duration > gun.Rate) && (gun.IsFiring == 1))
    4.                 {
    5.                     if (gun.Bullet != null)
    6.                     {
    7.                         gun.IsFiring = 0;
    8.                         statsComponent.shotsFired += 1;
    9.                         Entity e = EntityManager.Instantiate(gun.Bullet);
    10.                         Translation position = new Translation { Value = gunScript.AmmoStartLocation.transform.position };
    11.                         Rotation rotation = new Rotation { Value = gunScript.AmmoStartLocation.rotation };
    12.                         PhysicsVelocity velocity = new PhysicsVelocity
    13.                         {
    14.                             Linear = gunScript.AmmoStartLocation.forward * gun.Strength,
    15.                             Angular = float3.zero
    16.                         };
    17.                         EntityManager.SetComponentData(e, position);
    18.                         EntityManager.SetComponentData(e, rotation);
    19.                         EntityManager.SetComponentData(e, velocity);
    20.                         gunScript.CreateBulletInstance(e);
    21.  
    22.  
    23.                     }
    24.                     gun.Duration = 0;
    25.                 }