Exemplo n.º 1
0
    private void MovePorjectileWithHoming()
    {
        transform.position = Vector3.MoveTowards(transform.position, _creepTarget.transform.position, ProjectileMovementSpeed * Time.deltaTime); //Move the projectile
        float distanceToTarget = (_creepTarget.transform.position - transform.position).magnitude;                                               //IMPORTANT AND USEFULL. THIS IS HOW YOU CAN GET A DISTANCE

        //BETWEEN TWO "Vector3" POINTS AS A "float"!
        if (distanceToTarget < MinDistanceToDealDamage)   //Check if the projectile is close
        {
            OnCreepHit?.Invoke(_creepTarget, Damage);     //DELETE this later, as it is ONLY used for displaying DAMAGE NUMBERS

            _creepTarget._CreepHealth.DealDamage(Damage); //Fires the deal damage function in the creephealth reference
            //This is also why you sometimes want to declare FUNCTIONS with parameters. I would NOT have been able to specify the damage
            //from my damage var in THIS script, if the "DealDamage(float damage)" function took no "input".
            TurretOwner.ResetTurretProjectile();
            ObjectPooler.SetObjectToInactive(gameObject); //Return this projectile to the pool
        }
    }
Exemplo n.º 2
0
    private void MoveProjectileWithoutHoming()
    {
        if (t < 1f)
        {
            t += (Time.deltaTime * ProjectileMovementSpeed) / 10;
        }
        aPos = TurretOwner.transform.position + Vector3.up * 2.5f; //Needs improvement
        bPos = ((TurretOwner.transform.position + Vector3.up * topProjectileHight) + targetPos) / 2;
        cPos = targetPos;
        //New movement

        ABPos.position = Vector3.Lerp(aPos, bPos, t);                         //Move from A to B

        BCPos.position = Vector3.Lerp(bPos, cPos, t);                         //Move from B to C

        transform.position = Vector3.Lerp(ABPos.position, BCPos.position, t); //Move the projectile

        float distanceToTarget = (cPos - transform.position).magnitude;       //IMPORTANT AND USEFULL. THIS IS HOW YOU CAN GET A DISTANCE

        ////BETWEEN TWO "Vector3" POINTS AS A "float"!
        if (distanceToTarget < MinDistanceToDealDamage) //Check if the projectile is close
        {
            projectileIsFired = false;
            TurretOwner.ResetTurretProjectile();
            ObjectPooler.SetObjectToInactive(gameObject); //Return this projectile to the pool
            if (!DealsSplashDamage)
            {
                _creepTarget._CreepHealth.DealDamage(Damage); //Fires the deal damage function in the creephealth reference
                OnCreepHit?.Invoke(_creepTarget, Damage);     //DELETE this later, as it is ONLY used for displaying DAMAGE NUMBERS
            }
            if (DealsSplashDamage)
            {
                localSplashDamage.DealSplashDamage(transform.position, Damage); //Deal damage at location
            }
            t = 0f;
        }
    }