示例#1
0
 //Updates the local variables storing the mobs (known) location and the target's modified location.
 //These are only updated between skitter cycles to reduce accuracy and make it more bug-like.
 private void UpdateLocation()
 {
     location = transform.position;
     if (targetScatter > 0)
     {
         targetLocation = SeekingUtilities.Scatter(ControllerPlayer.PlayerLocation, targetScatter, targetScatter);
     }
 }
    //Runtime Initializations
    //Largely based on specific missile conditionals.
    private void OnEnable()
    {
        //Getting the location of the targety point.
        //Note, this is not a seeking missile, it merely fires toward the target point, it does not update the target after firing.
        GetTargetLocation();

        //Setting velocity
        GetComponent <Rigidbody2D>().velocity = SeekingUtilities.CalculateVelocity(gameObject, targetLocation, speed);

        //Setting destruction after missileLifespan seconds
        Destroy(gameObject, missileLifespan);

        //Setting damage to player damage if usePlayerDamage is true
        if (usePlayerDamage == true)
        {
            effectAmount = ControllerPlayer.PlayerDamage / ControllerGame.DifficultySetting();
        }
    }
示例#3
0
    //Update Functions
    #region

    //UpdateMovment
    //Updates the seekers velocity to aim toward the target. Does not update when very close to the target to reduce the Seekers short range accuracy.
    private void UpdateMovement(bool isMoving)
    {
        if (isMoving)
        {
            Vector2 distanceToTarget = location - targetLocation;
            if (distanceToTarget.sqrMagnitude > 5)
            {
                velocity = SeekingUtilities.CalculateVelocity(gameObject, targetLocation, speed);
            }

            //A lerp is used to smooth turning near the target
            body2D.velocity = Vector2.Lerp(body2D.velocity, velocity, .1f);

            //The sprite is rotated to face the direction of movement.
            body2D.transform.rotation = Quaternion.AngleAxis(Mathf.Atan2(body2D.velocity.y, body2D.velocity.x) * Mathf.Rad2Deg - 90, Vector3.forward);
        }
        else
        {
            //If isMoving is false then the velocity is zero.
            body2D.velocity = Vector2.zero;
        }
    }