Exemplo n.º 1
0
    void OnSmartTriggerStay2D(SmartContactPoint smartContactPoint)
    {
        //NOTE: dot product will be 1 if collision in perpendicular and opposite facing direction and 0 if horizontal and < 0 if perpendicular but in the same direction as facing direction
        float      dot        = Vector3.Dot(transform.up, smartContactPoint.normal);
        GameObject playerCtrl = smartContactPoint.otherCollider.gameObject;
        bool       isPlayer   = playerCtrl.tag == "Player";

        //Debug.Log("dot: " + dot);
        //Debug.DrawRay(smartContactPoint.point, smartContactPoint.normal, Color.white, 3f);
        if (isPlayer)
        {
            // if dot > 0, the collision is with top side
            if (dot > SmartRectCollider2D.k_OneSideSlopeNormThreshold)
            {
                // Kill the enemy, add player impulse
                smartContactPoint.otherCollider.RigidBody2D.velocity = new Vector2(smartContactPoint.otherCollider.RigidBody2D.velocity.x, 0f);
                smartContactPoint.otherCollider.RigidBody2D.AddForce(5f * smartContactPoint.otherCollider.RigidBody2D.transform.up, ForceMode2D.Impulse);
                PlatformCharacterController platformCtrl = playerCtrl.GetComponent <PlatformCharacterController>();
                if (platformCtrl)
                {
                    platformCtrl.PlatformCharacterPhysics.Velocity = 2 * platformCtrl.JumpingSpeed * smartContactPoint.otherCollider.RigidBody2D.transform.up;
                }
                Kill();
            }
            else
            {
                playerCtrl.SendMessage("Kill", SendMessageOptions.DontRequireReceiver);
            }
        }
    }
Exemplo n.º 2
0
    void OnSmartTriggerStay2D(SmartContactPoint smartContactPoint)
    {
        GameObject playerCtrl = smartContactPoint.otherCollider.gameObject;
        bool       isPlayer   = playerCtrl.tag == "Player";

        if (isPlayer)
        {
            playerCtrl.SendMessage("Kill", SendMessageOptions.DontRequireReceiver);
        }
    }
Exemplo n.º 3
0
 void OnSmartTriggerStay2D(SmartContactPoint smartContactPoint)
 {
     if (!m_isCollected && smartContactPoint.otherCollider.CompareTag("Player"))
     {
         m_isCollected = true;
         if (m_audioSource != null)
         {
             m_audioSource.Play();
         }
         GetComponent <Collider2D>().enabled = false;
         GetComponent <Renderer>().enabled   = false;
         Destroy(gameObject, m_audioSource.clip.length);
     }
 }