Example #1
0
    private void EnemyMove()
    {
        // 0,
        if (waypointIndex < waypointsList.Count)
        {
            //set the targetPosition to the next waypoint Position
            //targetposition: where we want to go
            var targetPosition = waypointsList[waypointIndex].transform.position;

            targetPosition.z = 0f;

            var enemyMovement = waveConfig.GetEnemyMoveSpeed() * Time.deltaTime;

            //move from current position, to target position, at enemyMovement speed
            transform.position = Vector2.MoveTowards(transform.position, targetPosition, enemyMovement);

            // check if we reached targetPosition
            if (transform.position == targetPosition)
            {
                waypointIndex++;
            }
        }
        //if enemy reached last     waypoint
        else
        {
            Destroy(gameObject);
        }
    }
    }    //This helps for the moving Enemy along a path

    private void EnemyMove()
    {
        if (waypointIndex < waypointsList.Count)
        {
            //Set the targetPosition to the next waypoint Position
            //TargetPosition: where we wish to go
            var targetPosition = waypointsList[waypointIndex].transform.position;

            targetPosition.z = 0f;
            //enemyMovment per frame
            var enemyMovment = waveConfig.GetEnemyMoveSpeed() * Time.deltaTime;

            //From current position it gets moved, to target position, at enemyMovement speed
            transform.position = Vector2.MoveTowards(transform.position, targetPosition, enemyMovment);

            //Check if we reached out targetPosition
            if (transform.position == targetPosition)
            {
                waypointIndex++;
            }
        }
        //If the enemy has reached the last waypoint
        else
        {
            Destroy(gameObject);
        }
    }
Example #3
0
    // Use this for initialization
    void Start()
    {
        waypoints = waveConfig.GetWaypoints();

        moveSpeed = waveConfig.GetEnemyMoveSpeed();

        transform.position = waypoints[waypointIndex].transform.position;
    }
Example #4
0
    private void Move()
    {
        if (wayPointIndex <= waypoints.Count - 1)
        {
            var targetPosition    = waypoints[wayPointIndex].transform.position;
            var movementThisFrame = waveConfig.GetEnemyMoveSpeed() * Time.deltaTime;
            transform.position = Vector2.MoveTowards(transform.position, targetPosition, movementThisFrame);

            if (transform.position == targetPosition)
            {
                wayPointIndex++;
            }
        }
        else
        {
            Destroy(gameObject);
        }
    }
Example #5
0
    private void Move()
    {
        if (currentWaypoint < waypoints.Count)
        {
            Vector3 nextWaypointHop      = waypoints[currentWaypoint].transform.position;
            float   movementSpeedInFrame = Time.deltaTime * waveConfig.GetEnemyMoveSpeed();
            transform.position = Vector2.MoveTowards(transform.position, nextWaypointHop, movementSpeedInFrame);

            if (transform.position == nextWaypointHop)
            {
                currentWaypoint++;
            }
        }
        else
        {
            //Destroy(gameObject);
            currentWaypoint = 0;
        }
    }
Example #6
0
    private void EnemyMove()
    {
        if (waypointIndex < waypointsList.Count)
        {
            var targetPosition = waypointsList[waypointIndex].transform.position;

            targetPosition.z = 0f;
            var enemyMovement = waveConfig.GetEnemyMoveSpeed() * Time.deltaTime;
            transform.position = Vector2.MoveTowards(transform.position, targetPosition, enemyMovement);

            if (transform.position == targetPosition)
            {
                waypointIndex++;
            }
        }

        else
        {
            Destroy(gameObject);
        }
    }
    void EnemyMove()
    {
        if (waypointIndex <= waypoints.Count - 1)
        {
            // Save the current waypoint in targetPosition
            // TargetPosition: where we want to go
            var targetPosition = waypoints[waypointIndex].transform.position;

            // To make sure z position is 0
            targetPosition.z = 0f;

            var movementThisFrame = waveConfig.GetEnemyMoveSpeed() * Time.deltaTime;
            // Move from the current position, to the target position, the maximum distance one can move
            transform.position = Vector2.MoveTowards(transform.position, targetPosition, movementThisFrame);

            // If we reached the target waypoint
            if (transform.position == targetPosition)
            {
                waypointIndex++;
            }
        }
    }
Example #8
0
    void EnemyMove()
    {
        // a check is made to make sure that there are coordinates left to traverse
        // in the list.
        if (wayPointIndex <= waypoints.Count - 1)
        // if(wayPointIndex < waypoints.Count)
        {
            var targetPosition = waypoints[wayPointIndex].transform.position;

            var movementThisFrame = waveConfig.GetEnemyMoveSpeed() * Time.deltaTime;
            //making the enemy movement frame independent (moving at the same speed on every PC).

            /*
             * MoveTowards is a method found in the Vector2 class. This method returns
             * a temporarily coordinate so that it starts moving the object from the
             * current position to the targetposition. Different coordinates are
             * constantly returned to make the object move "slowly" in a path to the
             * targetPosition, otherwise, the object would go immediately to the
             * targetPosition.
             * The value of the coordinate depends on the speed which is passed as the
             * last parameter.
             */

            transform.position = Vector2.MoveTowards(transform.position, targetPosition,
                                                     movementThisFrame);

            //check if current position is equal to that of the destination so that we
            //can start moving towards the next coordinate (if there are any left)
            if (transform.position == targetPosition)
            {
                wayPointIndex++;
            }
        }
        else // if there are no coordinates left in our list, destroy the enemy
        {
            Destroy(gameObject);
        }
    }
    private void EnemyMove()
    {
        if (waypointIndex <= waypoints.Count - 1)
        {
            var targetPosition = waypoints[waypointIndex].transform.position;

            targetPosition.z = 0f;

            var enemyMovement = waveConfig.GetEnemyMoveSpeed() * Time.deltaTime;

            transform.position = Vector2.MoveTowards(transform.position, targetPosition, enemyMovement);

            if (transform.position == targetPosition)
            {
                waypointIndex++;
            }
        }
        else
        {
            Destroy(gameObject);
            FindObjectOfType <GameSession>().AddToScore(scoreValue);
        }
    }
Example #10
0
    void EnemyMove()
    {
        if (wayPointIndex < wayPoints.Count)
        //if(wayPointIndex <= wayPoints.Count - 1)
        {
            /* since the enemy movement method will be called every frame, the movement's speed
             * will be frame dependant. Just like we did for the player, we are using Time.deltaTime
             * to make the speed frame independant.
             */
            var movementThisFrame = waveConfig.GetEnemyMoveSpeed() * Time.deltaTime;
            var targetPosition    = wayPoints[wayPointIndex].position;

            /* MoveTowards is a method found in the Vector2 class and it basically moves an object
             * from the current position to a target position/destination by returning a new
             * position every frame to slowly move the object to the target step by step and
             * making it look as if it is moving along a path.
             */

            transform.position = Vector2.MoveTowards(transform.position, targetPosition,
                                                     movementThisFrame);

            if (transform.position == targetPosition)
            {
                wayPointIndex++; // wayPointIndex = wayPointIndex + 1;
            }
        }
        else // if there are no more coordinates left in the list
        {
            /* The gameObject keyword refers to the object which contains the current script.
             * This is important since we are going to have multiple Enemies and we need to one
             * which one to destroy. The one which has moved along ALL the coordinates (so the one
             * that reached this else statement) will be destroyed.
             */
            Destroy(gameObject);
        }
    }