Esempio n. 1
0
            public void Execute(Entity e)
            {
                AIEntity entity = (AIEntity)e;

                // check point 1
                {
                    // damaged first
                    if (entity.triggerDamage)
                    {
                        entity.target        = entity.triggerDamage;
                        entity.triggerDamage = null;
                        entity.Event         = eEntityState.Search;
                        return;
                    }

                    // check target in sight
                    if (Facade_AI.DetectTarget(entity.property, entity.property.tb.sightRange, out entity.target))
                    {
                        Debug.Log("- Detect palyer!!");

                        // check runaway condition (life)
                        if (entity.Ai.IsRunawayCondition())
                        {
                            entity.Event = eEntityState.Runaway;
                            return;
                        }
                        // check distance for attacking or
                        Vector3 distance = entity.target.transform.position - entity.property.transform.position;
                        if (distance.magnitude < entity.property.tb.attackRange)
                        {
                            entity.Event = eEntityState.Attack;
                        }
                        else
                        {
                            entity.Event = eEntityState.Chase;
                        }
                        return;
                    }
                }

                // check point 2
                {
                    // change next moving position
                    if (!entity.Ai.IsMoving)
                    {
                        if (Facade_NavMesh.RandomRangePoint(
                                entity.property.transform.position,
                                entity.property.tb.wander_min_range,
                                entity.property.tb.wander_max_range, out entity.destination))
                        {
                            entity.Ai.agent.destination = entity.destination;
                        }
                    }
                }
            }
Esempio n. 2
0
        // spawn randowm object in type
        public PooledObject Spawn(eSpawn type, Vector3 initPos = default(Vector3))
        {
            PooledObject[] objPrefab = null;
            Transform[]    posPrefab = null;
            switch (type)
            {
            case eSpawn.Player:
                objPrefab = objPrefabPlayer;
                posPrefab = spots;
                break;

            case eSpawn.NonPlayer:
                objPrefab = objPrefabNPC;
                posPrefab = spots;
                break;
            }
            int index = Random.Range(0, posPrefab.Length);

            if (objPrefab != null && posPrefab != null)
            {
                const int tryCnt = 5;
                if (initPos == default(Vector3))
                {
                    for (int i = 0; i < tryCnt; ++i)
                    {
                        if (Facade_NavMesh.RandomRangePoint(posPrefab[index].position, 0, 10f, out initPos))
                        {
                            break;
                        }
                    }
                }

                // fails to found the position
                if (initPos == default(Vector3))
                {
                    return(null);
                }

                var objSpawn = SpawnObject(objPrefab[Random.Range(0, objPrefab.Length)], initPos);
                // save for searching in AI
                ObjectProperty property = objSpawn as ObjectProperty;
                if (null != property)
                {
                    All.Add(property);
                }
                return(objSpawn);
            }

            return(null);
        }
Esempio n. 3
0
        // Update is called once per frame
        void FixedUpdate()
        {
            if (isHit)
            {
                return;
            }
            int maskLayer = Facade_NavMesh.GetLayerMask(
                ((owner.ally == AliasType.NonPlayer)? LayerId.PlayerAllias : LayerId.NonPlayer),
                LayerId.Geometry,
                LayerId.Obstacle);
            // Vector3 fwd = transform.TransformDirection(Vector3.forward);
            RaycastHit hit;

            if (Physics.Raycast(transform.position, direction, out hit, force * Time.fixedDeltaTime, maskLayer))
            {
                transform.position += (direction * hit.distance);
                OnTriggerEnter(hit.collider);
            }
            else
            {
                transform.position += (direction * force * Time.fixedDeltaTime);
            }
        }