Example #1
0
    public Vector2 ObjectPositionAtMapPoint(MapPoint mapPoint)
    {
        Vector2 worldPosition = MapLayout.ScreenPointFromMapPoint(mapPoint);
        Tile    tile          = TileAtMapPoint(mapPoint);

        Debug.Log("Tile centre :" + tile.centreX + "," + tile.centreY);

        worldPosition.x += (tile.centreX / 100.0f) - 0.5f;
        worldPosition.y += (tile.centreY / 100.0f);

        return(worldPosition);
    }
Example #2
0
    IEnumerator WalkToStep(WalkingStep ws)
    {
        var     startPosition            = transform.localPosition;
        Vector2 destinationWorldPosition = MapLayout.ScreenPointFromMapPoint(ws.step.MapPoint);
        Vector2 fromWorldPosition        = MapLayout.ScreenPointFromMapPoint(ws.fromPoint);

        Tile fromTile, toTile;

        fromTile = controller.map.TileAtMapPoint(ws.fromPoint);
        toTile   = controller.map.TileAtMapPoint(currentPosition);

        float timer = 0.0f;

        Vector2 edge    = fromTile.edgeForDirection(ws.direction);
        float   divisor = 1.0f;

        if (edge.x != -1 && edge.y != -1)
        {
            var edgeDestination = new Vector3(fromWorldPosition.x + ((edge.x - 50.0f) / 100.0f), fromWorldPosition.y + (edge.y / 100.0f), 0);
            while (transform.localPosition != edgeDestination)
            {
                transform.localPosition = Vector3.MoveTowards(startPosition, edgeDestination, walkingSpeed * timer);
                timer += Time.fixedDeltaTime;

                yield return(new WaitForEndOfFrame());
            }

            divisor       = 2.0f;
            startPosition = edgeDestination;
        }

        var destination = new Vector3(destinationWorldPosition.x, destinationWorldPosition.y + (toTile.centreY / 100.0f));

        timer = 0.0f;

        while (transform.localPosition != destination)
        {
            transform.localPosition = Vector3.MoveTowards(startPosition, destination, walkingSpeed * timer);
            timer += Time.fixedDeltaTime;

            yield return(new WaitForEndOfFrame());
        }
    }