Esempio n. 1
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.GetComponent <SpikeScript>() != null && canGetHurt && !dead)
        {
            //ground is spikes
            HurtPlayer(8, 5);
        }
        else if (collision.gameObject.tag == "Pit")
        {
            //hit a pit, fall
            FallInPit();
        }
        else if (collision.gameObject.tag == "SavePoint")
        {
            MultiplayerRunManager.Instance.player2RespawnPoint = collision.gameObject.transform.position;
        }
        //check to see if hit a person with our axe
        Slasher      slash  = collision.gameObject.GetComponentInParent <Slasher>();
        SlasherLocal lslash = collision.gameObject.GetComponentInParent <SlasherLocal>();

        if ((slash || lslash) && collision.gameObject.transform.parent != transform && canGetHurt && !collision.gameObject.CompareTag("Hurtbox"))
        {
            //TODO: BOTH trigger and RigidBody2D receive this message. Check here to see if the trigger involved is ours or not (if so, this is our hit, do nothing, else, we were hit by someone else, get hurt)
            Vector2 dir   = (transform.position - collision.gameObject.transform.parent.position).normalized;
            float   angle = Vector2.SignedAngle(Vector2.right, dir);
            print("DIRECTION: " + dir + "ANGLE: " + angle);
            HurtPlayer(0, -1, true, angle);
        }
    }
Esempio n. 2
0
 /// <summary>
 /// Handles collision logic
 ///
 /// SERVER: handles collisions
 /// </summary>
 /// <param name="collision"></param>
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (isServer)
     {
         //if weapon, decrease health
         if (collision.gameObject.CompareTag("Weapons"))
         {
             Slasher      sl  = collision.gameObject.GetComponentInParent <Slasher>();
             SlasherLocal lsl = null;
             if (!sl)
             {
                 lsl = collision.gameObject.GetComponentInParent <SlasherLocal>();
                 if (lsl)
                 {
                     //notify server
                     DamageBoss(lsl.damagePerSwing);
                     //increment that player's score
                     int scoringPlayer = collision.gameObject.GetComponentInParent <LocalPlayerIdentity>().ID;
                     BossManager.Instance.UpdateScore(scoringPlayer, lsl.damagePerSwing);
                 }
             }
             if (sl)
             {
                 //notify server
                 DamageBoss(sl.damagePerSwing);
                 //increment that player's score
                 NetworkConnection scoringPlayer = collision.gameObject.GetComponentInParent <NetworkIdentity>().connectionToClient;
                 BossManager.Instance.UpdateScore(scoringPlayer.connectionId, sl.damagePerSwing);
             }
         }
     }
 }
Esempio n. 3
0
 // Start is called before the first frame update
 void Start()
 {
     mvr = GetComponent <PlayerMovement>();
     if (!mvr)
     {
         lmvr = GetComponent <PlayerMovementLocal>();
     }
     slash = GetComponent <Slasher>();
     if (!slash)
     {
         lslash = GetComponent <SlasherLocal>();
     }
     colHand = GetComponent <CollisionHandler>();
     if (!colHand)
     {
         lcolHand = GetComponent <CollisionHandlerLocal>();
     }
     rb           = GetComponent <Rigidbody2D>();
     anim         = GetComponent <Animator>();
     achievements = AcheivementScript.Instance;
 }
Esempio n. 4
0
    /// <summary>
    /// Toggles collision and movement logic for pits
    /// </summary>
    public void ToggleInteractivity(bool toggle)
    {
        //toggle movement
        PlayerMovementLocal lm = GetComponent <PlayerMovementLocal>();

        if (toggle)
        {
            lm.SetMove();
        }
        else
        {
            lm.DisableMove();
        }
        //toggle all triggers/hitboxes in system, toggle weapons off but never on
        foreach (BoxCollider2D col in GetComponentsInChildren <BoxCollider2D>())
        {
            if (!col.gameObject.CompareTag("Weapons") || !toggle)
            {
                col.enabled = toggle;
            }
        }
        GetComponent <BoxCollider2D>().enabled = toggle;
        //toggle velocity
        if (!toggle)
        {
            rb.constraints = RigidbodyConstraints2D.FreezeAll;
        }
        else
        {
            rb.constraints = RigidbodyConstraints2D.FreezeRotation;
        }

        SlasherLocal sl = GetComponent <SlasherLocal>();

        if (sl.isSwinging)
        {
            sl.EndSlash();
        }
    }