Example #1
0
    // Update is called once per frame
    void Update()
    {
        //chase
        if (Vector3.Distance(player.position, transform.position) <= distanceToPlayer) //if distance between player and cube is less than defined distance
        {
            //update direction
            moveDir = waypoint.GetDirectionToPlayer(transform, player);
        }
        else
        {
            //move direction and position of box
            moveDir = waypoint.GetDirection(transform); //accesses whole graph of each waypoint-> is getting current location and returns move direction which is also normalized
        }

        if (waypoint.AwayFromWaypoint(transform, awayFromHome)) //pass in cube current location and if function returns true or false
        {
            moveDir = waypoint.GetDirection(transform);         //move back to taget
        }

        transform.position += moveDir * moveSpeed * Time.deltaTime; //update position

        //This is where the rotation is controlled
        //transform.rotation = Quaternion.LookRotation(moveDir);//maipulate rotation, each time change direction, also moves rotation
    }