Пример #1
0
 public bool IsUpdated(EntityManager entityManager, Entity entity)
 {
     pd = entityManager.GetComponentData <PhysicsDamping>(entity);
     if (pd.Angular != Angular || pd.Linear != Linear)
     {
         return(false);
     }
     return(true);
 }
 private static MotionData CreateMotionData(
     Translation position, Rotation orientation,
     PhysicsMass physicsMass, PhysicsDamping damping,
     float gravityFactor)
 {
     return(new MotionData
     {
         WorldFromMotion = new RigidTransform(
             math.mul(orientation.Value, physicsMass.InertiaOrientation),
             math.rotate(orientation.Value, physicsMass.CenterOfMass) + position.Value
             ),
         BodyFromMotion = physicsMass.Transform,
         LinearDamping = damping.Linear,
         AngularDamping = damping.Angular,
         GravityFactor = gravityFactor
     });
 }
Пример #3
0
        public static bool SetPhysicsDamping(EntityManager entityManager, Entity entity, ByteString30 name, PokemonEntityData ped)
        {
            PhysicsDamping ps = new PhysicsDamping
            {
                Angular = 0.05f,
                Linear  = 0.01f
            };

            switch (name.ToString())
            {
            case "Electrode":
                ps = new PhysicsDamping
                {
                    Angular = 0.5f,
                    Linear  = 0.1f
                };
                break;

            default: Debug.LogError("failed to find PhysicsDamping for pokemon \"" + name + "\""); break;
            }
            try
            {
                if (entityManager.HasComponent <PhysicsDamping>(entity))
                {
                    entityManager.SetComponentData <PhysicsDamping>(entity, ps);
                }
                else
                {
                    entityManager.AddComponentData(entity, ps);
                }
                return(true);
            }
            catch
            {
                Debug.LogError("Failed to set AngularDamping!");
            }
            return(false);
        }
                public unsafe void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
                {
                    NativeArray <Translation>          chunkPositions      = chunk.GetNativeArray(PositionType);
                    NativeArray <Rotation>             chunkRotations      = chunk.GetNativeArray(RotationType);
                    NativeArray <PhysicsVelocity>      chunkVelocities     = chunk.GetNativeArray(PhysicsVelocityType);
                    NativeArray <PhysicsMass>          chunkMasses         = chunk.GetNativeArray(PhysicsMassType);
                    NativeArray <PhysicsDamping>       chunkDampings       = chunk.GetNativeArray(PhysicsDampingType);
                    NativeArray <PhysicsGravityFactor> chunkGravityFactors = chunk.GetNativeArray(PhysicsGravityFactorType);

                    int motionStart   = firstEntityIndex;
                    int instanceCount = chunk.Count;

                    bool hasChunkPhysicsGravityFactorType = chunk.Has(PhysicsGravityFactorType);
                    bool hasChunkPhysicsDampingType       = chunk.Has(PhysicsDampingType);
                    bool hasChunkPhysicsMassType          = chunk.Has(PhysicsMassType);

                    // Note: Transform and AngularExpansionFactor could be calculated from PhysicsCollider.MassProperties
                    // However, to avoid the cost of accessing the collider we assume an infinite mass at the origin of a ~1m^3 box.
                    // For better performance with spheres, or better behavior for larger and/or more irregular colliders
                    // you should add a PhysicsMass component to get the true values
                    var defaultPhysicsMass = new PhysicsMass()
                    {
                        Transform              = RigidTransform.identity,
                        InverseMass            = 0.0f,
                        InverseInertia         = float3.zero,
                        AngularExpansionFactor = 1.0f,
                    };

                    // Create motion velocities
                    var defaultInverseInertiaAndMass = new float4(defaultPhysicsMass.InverseInertia, defaultPhysicsMass.InverseMass);

                    for (int i = 0, motionIndex = motionStart; i < instanceCount; i++, motionIndex++)
                    {
                        MotionVelocities[motionIndex] = new MotionVelocity
                        {
                            LinearVelocity         = chunkVelocities[i].Linear,  // world space
                            AngularVelocity        = chunkVelocities[i].Angular, // inertia space
                            InverseInertiaAndMass  = hasChunkPhysicsMassType ? new float4(chunkMasses[i].InverseInertia, chunkMasses[i].InverseMass) : defaultInverseInertiaAndMass,
                            AngularExpansionFactor = hasChunkPhysicsMassType ? chunkMasses[i].AngularExpansionFactor : defaultPhysicsMass.AngularExpansionFactor,
                        };
                    }

                    // Note: these defaults assume a dynamic body with infinite mass, hence no damping
                    var defaultPhysicsDamping = new PhysicsDamping()
                    {
                        Linear  = 0.0f,
                        Angular = 0.0f,
                    };

                    // Note: if a dynamic body infinite mass then assume no gravity should be applied
                    float defaultGravityFactor = hasChunkPhysicsMassType ? 1.0f : 0.0f;

                    // Create motion datas
                    for (int i = 0, motionIndex = motionStart; i < instanceCount; i++, motionIndex++)
                    {
                        MotionDatas[motionIndex] = CreateMotionData(
                            chunkPositions[i], chunkRotations[i],
                            hasChunkPhysicsMassType ? chunkMasses[i] : defaultPhysicsMass,
                            hasChunkPhysicsDampingType ? chunkDampings[i] : defaultPhysicsDamping,
                            hasChunkPhysicsGravityFactorType ? chunkGravityFactors[i].Value : defaultGravityFactor);
                    }
                }
Пример #5
0
 public void Update(EntityManager entityManager, Entity entity)
 {
     pd      = entityManager.GetComponentData <PhysicsDamping>(entity);
     Angular = pd.Angular;
     Linear  = pd.Linear;
 }