コード例 #1
0
 private void AddTransformRefs(Transform t)
 {
     if (t.GetComponent <Collider>() != null && t.GetComponent <RootTransformRefEntity>() == null)
     {
         RootTransformRefEntity rootTransformRefEntity = t.gameObject.AddComponent <RootTransformRefEntity>();
         rootTransformRefEntity.RootTransform = base.transform;
     }
     foreach (object obj in t)
     {
         Transform t2 = (Transform)obj;
         AddTransformRefs(t2);
     }
 }
コード例 #2
0
ファイル: ThinAnimatorSDX.cs プロジェクト: 7D2DMods/NPCs
 private void AddTransformRefs(Transform t)
 {
     if (t.GetComponent <Collider>() != null && t.GetComponent <RootTransformRefEntity>() == null)
     {
         RootTransformRefEntity root = t.gameObject.AddComponent <RootTransformRefEntity>();
         root.RootTransform = this.transform;
         // Debug.Log("Added root ref on " + t.name + " tag " + t.tag);
     }
     foreach (Transform tran in t)
     {
         AddTransformRefs(tran);
     }
 }
コード例 #3
0
    public void FindAndKillSurroundingEntities()
    {
        //if (entityDamage == 0 || entityVehicle.lastControllerVelocityMagnitude < 5f || Time.time - entityHitAgainDelay < lastEntityHitTime)
        if (entityDamage == 0 || lastControllerVelocityMagnitude < entityHitMinSpeed)
        {
            //DebugMsg("NOT damaging entity: entityDamage = " + entityDamage.ToString() + " | lastControllerVelocityMagnitude = " + entityVehicle.lastControllerVelocityMagnitude.ToString("0.000"));
            return;
        }
        else
        {
            //DebugMsg("lastControllerVelocityMagnitude = " + entityVehicle.lastControllerVelocityMagnitude.ToString("0.000"));
        }

        // Try-catch for now because of an error with Bandits and survivors
        try
        {
            Vector3    b = new Vector3(0f, entityVehicle.m_characterController.height / 2f, 0f);
            RaycastHit raycastHit;
            //if (Physics.CapsuleCast(entityVehicle.position - b, entityVehicle.position + b, destructionRadius, entityVehicle.motion.normalized, out raycastHit, entityVehicle.motion.magnitude, -1) && raycastHit.collider != null)
            if (Physics.CapsuleCast(entityVehicle.position - b, entityVehicle.position + b, destructionRadius, entityVehicle.motion.normalized, out raycastHit, destructionRadius + 1, -1) && raycastHit.collider != null)
            {
                RootTransformRefEntity component = raycastHit.collider.gameObject.GetComponent <RootTransformRefEntity>();
                if (component)
                {
                    EntityAlive entityAlive = component.RootTransform.GetComponent <Entity>() as EntityAlive;
                    //if (entityAlive != null && entityAlive != entityVehicle.AttachedEntities && entityAlive.Spawned && !entityAlive.IsDead())
                    if (entityAlive != null && entityAlive != entityVehicle.AttachedEntities && !entityAlive.IsDead() && !(entityAlive.entityId == lastHitEntityId && Time.time - entityHitAgainDelay < lastEntityHitTime))
                    {
                        int damage = entityDamage;
                        entityHitSpeedRatio = CustomVehiclesUtils.GetRatio(Mathf.Clamp(lastControllerVelocityMagnitude, entityHitMinSpeed, 18f), entityHitMinSpeed, 18f) + 1f;
                        entityHitDamage     = Mathf.RoundToInt((float)damage * entityHitSpeedRatio);
                        bool isCritical = lastControllerVelocityMagnitude > entityCriticalHitMinSpeed;
                        // Doing this in order to properly kill entities. Otherwise they die instantly without animation, and animal corpses disappear.
                        if (entityHitDamage > entityAlive.Health)
                        {
                            entityHitDamage = entityAlive.Health;
                            isCritical      = true;
                        }
                        DamageSourceEntity damageSourceEntity;
                        if (isCritical)
                        {
                            damageSourceEntity = new DamageSourceEntity(EnumDamageSourceType.Melee, entityVehicle.player.entityId, -raycastHit.normal);
                        }
                        else
                        {
                            damageSourceEntity = new DamageSourceEntity(EnumDamageSourceType.Melee, entityVehicle.player.entityId, -raycastHit.normal, raycastHit.transform.name, raycastHit.point, Vector2.zero);
                        }
                        //DamageSourceEntity damageSourceEntity = new DamageSourceEntity(EnumDamageSourceType.Melee, entityVehicle.player.entityId, -raycastHit.normal, raycastHit.transform.name, raycastHit.point, Vector2.zero);
                        lastHitEntityId = entityAlive.entityId;
                        entityAlive.DamageEntity(damageSourceEntity, entityHitDamage, isCritical, isCritical? 3f : 2f);

                        //DebugMsg("Damage Entity: " + entityAlive.entityId + " | lastControllerVelocityMagnitude = " + lastControllerVelocityMagnitude.ToString("0.000") + " (hit speed ratio = " + entityHitSpeedRatio.ToString("0.000")
                        //    + ") | damage = " + entityHitDamage.ToString("0.000") + " (" + entityAlive.Health.ToString() + "/" + entityAlive.GetMaxHealth().ToString() + ") | hit transform name = " + raycastHit.transform.name + " | critical = " + isCritical.ToString());

                        float vehDmg = (((float)entityAlive.GetMaxHealth()) / 3000.0f) * vehicleDamageFactor_entities * entityHitSpeedRatio;
                        DamageVehicle(vehDmg, 2f);
                        lastEntityHitTime = Time.time;
                    }
                }
            }
        }
        catch (System.Exception e)
        {
            Debug.LogError("An error occurred: " + e);
        }
    }