Example #1
0
    protected override void Initialize()
    {
        base.Initialize();

        sphereCollider   = GetComponent <SphereCollider>();
        trailRenderer    = GetComponent <TrailRenderer>();
        turretController = BattleRoot.BattleController.TurretController;

        idleState   = new IdleState(this);
        thrownState = new ThrownState(this);
    }
Example #2
0
 public void GetThrown(Vector3 direction)
 {
     if (beingCarried == CarriedState.CARRIED)
     {
         beenThrown = ThrownState.THROWN;
         beingCarried = CarriedState.NOT_CARRIED;
         transform.parent = null;
         rb.isKinematic = false;
         rb.AddForce(direction, ForceMode.VelocityChange);
     }
 }
Example #3
0
    /// <summary>
    /// Check if the Throwable is grounded
    /// TODO: implement a damage cooldown timer (sometimes players get collided with multiple times very quickly)
    /// </summary>
    void CheckGrounded()
    {
        RaycastHit hit;

        if (Physics.Raycast(transform.position, Vector3.down, out hit, 1f))
        {
            if (hit.collider.gameObject.tag == "LevelGeometry" && rb.velocity == Vector3.zero)
            {
                beenThrown = ThrownState.NOT_THROWN;
                holder = null;
            }
        }
    }
Example #4
0
    // Update is called once per frame
    void FixedUpdate()
    {
        switch (thrownState)
        {
        case ThrownState.Moving:
            Vector3 distance = (target - this.transform.position);
            if (distance.magnitude < 2 * thrownVelocity)
            {
                thrownState         = ThrownState.Landed;
                filter.useLayerMask = true;
                filter.layerMask    = layermask;
                this.GetComponent <SpriteRenderer>().enabled = false;
            }
            this.transform.position   += (target - this.transform.position).normalized * thrownVelocity;
            this.transform.eulerAngles = (new Vector3(0, 0, this.transform.rotation.eulerAngles.z + angularVelocity));
            break;

        case ThrownState.Landed:
            //get objects to damage
            Physics2D.OverlapCircle(this.transform.position, damageRange, filter, damageList);
            //deal damage
            Health health;
            for (int i = 0; i < damageList.Count; i++)
            {
                if (damageList[i].gameObject.TryGetComponent(out health))
                {
                    health.DealDamage(damage, damageType, null);
                    ParticleSystemPool.Instance.EmitParticle(particleAtDamagable, damageList[i].transform.position, particleQuantityPerTickAtDamagable);
                }
            }
            ParticleSystemPool.Instance.EmitParticle(particleAtLanding, this.transform.position, particleQuantityPerTick, true);
            damageLength--;
            if (damageLength <= 0)
            {
                Destroy(this);
            }
            particleQuantityPerTickAtDamagable -= decrementParticleQuantityAtDamagable;
            break;
        }
    }