Beispiel #1
0
        public override void Update()
        {
            float range = 50.0f;

            timeShot += Time.deltaTime;
            float fov = Mathf.PI / 4.0f;
            // Can I see the leader?
            GameObject leader = SteeringManager.Instance().currentScenario.leader;

            if ((leader.transform.position - entity.transform.position).magnitude > range)
            {
                entity.GetComponent <StateMachine>().SwicthState(new IdleState(entity));
            }
            else
            {
                float   angle;
                Vector3 toEnemy = (leader.transform.position - entity.transform.position);
                toEnemy.Normalize();
                angle = (float)Math.Acos(Vector3.Dot(toEnemy, entity.transform.forward));
                if (angle < fov)
                {
                    if (timeShot > 0.25f)
                    {
                        GameObject lazer = new GameObject();
                        lazer.AddComponent <Lazer>();
                        lazer.transform.position = entity.transform.position;
                        lazer.transform.forward  = entity.transform.forward;
                        timeShot = 0.0f;
                    }
                }
            }
        }
Beispiel #2
0
 public override void Enter()
 {
     entity.GetComponent <SteeringBehaviours>().turnOffAll();
     entity.GetComponent <SteeringBehaviours>().OffsetPursuitEnabled     = true;
     entity.GetComponent <SteeringBehaviours>().ObstacleAvoidanceEnabled = true;
     entity.GetComponent <SteeringBehaviours>().offset = new Vector3(0, 0, 5);
     entity.GetComponent <SteeringBehaviours>().leader = SteeringManager.Instance().currentScenario.leader;
 }
        public override void Update()
        {
            float range = 50.0f;
            // Can I see the leader?
            GameObject leader = SteeringManager.Instance().currentScenario.leader;

            if ((leader.transform.position - entity.transform.position).magnitude < range)
            {
                // Is the leader inside my FOV
                entity.GetComponent <StateMachine>().SwicthState(new AttackingState(entity));
            }
        }
Beispiel #4
0
        public GameObject CreateCamFollower(GameObject leader, Vector3 offset)
        {
            GameObject camFollower = new GameObject();

            camFollower.tag = "camFollower";
            camFollower.AddComponent <SteeringBehaviours>();
            camFollower.GetComponent <SteeringBehaviours>().leader = leader;
            camFollower.GetComponent <SteeringBehaviours>().offset = offset;
            camFollower.transform.position = leader.transform.TransformPoint(offset);
            camFollower.GetComponent <SteeringBehaviours> ().OffsetPursuitEnabled = true;
            //camFighter.GetComponent<SteeringBehaviours>().turnOn(SteeringBehaviours.behaviour_type.wall_avoidance);
            camFollower.GetComponent <SteeringBehaviours> ().ObstacleAvoidanceEnabled = true;
            SteeringManager.Instance().camFighter = camFollower;
            GameObject.FindGameObjectWithTag("MainCamera").transform.position = camFollower.transform.position;

            return(camFollower);
        }