Exemplo n.º 1
0
    public override void Update(Npc npc)
    {
        closestBall = npc.FindClosestBall(npc.transform.position);
        if (closestBall != null)
        {
            npc.GetComponent <NpcController>().GoToBall(closestBall);
        }
        //OverlapCapsule calculations based on this: https://roundwide.com/physics-overlap-capsule/
        var center = npc.transform.TransformPoint(npcCollider.center);
        var size   = new Vector3(npcCollider.radius, npcCollider.height, npcCollider.radius); //the code given in the above link for this line is WRONG! Don't convert to world position!
        var radius = size.x;                                                                  //the CharacterController radius + skinWidth MUST be smaller than the CapsuleCollider radius or else it won't detect collisions!
        var height = size.y;
        var bottom = new Vector3(center.x, center.y - height / 2 + radius, center.z);
        var top    = new Vector3(center.x, center.y + height / 2 - radius, center.z);
        //the following code works similarly to BlastballStateThrown - refer to that for explanation
        bool checkCapsule = Physics.CheckCapsule(top, bottom, radius, ballMask);

        Physics.OverlapCapsuleNonAlloc(top, bottom, radius, overlapBall, ballMask);
        if (!oldCheckCapsule && checkCapsule)
        {
            npc.npcBall = overlapBall[0].gameObject;
        }
        oldCheckCapsule = checkCapsule;

        //change state
        if (npc.npcBall != null)
        {
            npc.ChangeState(npc.stateHasBall);
        }
    }
Exemplo n.º 2
0
    public override void Update(Npc npc)
    {
        heldTime += Time.deltaTime;
        npc.npcBall.transform.position = npc.transform.position + npc.transform.right * npc.heldBallLocation.x + npc.transform.up * npc.heldBallLocation.y + npc.transform.forward * npc.heldBallLocation.z; //move the ball to the npc's hand

        if (heldTime >= Random.Range(Npc.minHeldTime, Npc.maxHeldTime))                                                                                                                                      //throw the ball
        {
            if (npc.npcBall.GetComponent <Ball>().Type == Ball.BallType.Blastball)
            {
                closestTeammate = npc.FindClosestTeammate(npc.transform.position, team);
            }
            else if (npc.npcBall.GetComponent <Ball>().Type == Ball.BallType.Burstball)
            {
                closestTeammate = npc.FindClosestTeammate(npc.transform.position, opposingTeam);
            }
            npc.GetComponent <NpcController>().FaceTarget(closestTeammate.transform.position);
            turnTime++;
            if (turnTime >= NpcController.TurnTime)
            {
                Vector3 viewDirection = npc.transform.forward;              //get the direction of the npc
                viewDirection.Normalize();
                viewDirection.y += 3f;                                      //TODO: get rid of this magic number
                npc.npcBall.GetComponent <Ball>().ThrowBall(viewDirection); //throw ball in direction of the npc
                npc.ChangeState(npc.stateEmptyHanded);                      //change state
            }
        }
    }
Exemplo n.º 3
0
    public void OnAction(bool fright = true)
    {
        if (!fright && _type != Furniture.Puerta)
        {
            return;
        }
        if ((_useCount != 0 && _state == State.IDLE) || (_state == State.RUNNING && !fright))
        {
            _timeleft = _timeout;
            _state    = State.RUNNING;

            List <Npc> npcs = _game.GetNpcs();

            if (fright)
            {
                for (int i = 0; i < npcs.Count; i++)                 //fright people
                {
                    Npc n = npcs[i];

                    if (n.GetCurrentRoom() == _room)
                    {
                        n.ChangeState(_type);
                    }
                }
            }

            if (_animated)
            {
                if (_toggleable)
                {
                    _toggled = !_toggled;
                }

                GetComponent <SpriteAnimator>().PlaySpriteAnimator();
            }

            if (_sound != null && !_playing && SettingsController.instance.PlaySFX())             //sound
            {
                _playing = true;
                //AudioSource[] aud = GameObject.FindObjectsOfType(typeof(AudioSource)) as AudioSource[];
                AudioSource.PlayClipAtPoint(_sound, GameObject.Find("Main Camera").transform.position);
            }

            if (_type == Furniture.Luz)            //ligths
            {
                GameObject go = GameObject.Find("Luces/" + _room);
                go.GetComponent <SpriteRenderer>().enabled = !go.GetComponent <SpriteRenderer>().enabled;
            }

            //Todo reproduce animation for this actuator
            if (_useCount > 0) //Only rest if non-infinite uses
            {
                _useCount--;

                if (_useCount == 0)
                {
                    if (_broken != null)
                    {
                        GetComponent <SpriteRenderer>().sprite = _broken;
                    }
                }
            }
        }
    }