Esempio n. 1
0
    private OrthoDir CalculateDirection()
    {
        OrthoDir  normalDir = Parent().GetComponent <CharaEvent>().facing;
        MapCamera cam       = Application.isPlaying ? Global.Instance().Maps.Camera : FindObjectOfType <MapCamera>();

        if (!cam || !dynamicFacing)
        {
            return(normalDir);
        }

        Vector3 ourScreen    = cam.GetCameraComponent().WorldToScreenPoint(parentEvent.transform.position);
        Vector3 targetWorld  = MapEvent3D.TileToWorldCoords(parentEvent.positionXY + normalDir.XY());
        Vector3 targetScreen = cam.GetCameraComponent().WorldToScreenPoint(targetWorld);
        Vector3 delta        = targetScreen - ourScreen;

        return(OrthoDirExtensions.DirectionOf(new Vector2(delta.x, -delta.y)));
    }
Esempio n. 2
0
    private OrthoDir DirectionRelativeToCamera()
    {
        MapCamera cam = Application.isPlaying ? Global.Instance().Maps.camera : FindObjectOfType <MapCamera>();

        if (!cam || !dynamicFacing)
        {
            return(facing);
        }

        Vector3 ourScreen   = cam.GetCameraComponent().WorldToScreenPoint(transform.position);
        Vector3 targetWorld = ((MapEvent3D)parent).TileToWorldCoords(parent.position + facing.XY3D());

        targetWorld.y = parent.transform.position.y;
        Vector3 targetScreen = cam.GetCameraComponent().WorldToScreenPoint(targetWorld);
        Vector3 delta        = targetScreen - ourScreen;

        return(OrthoDirExtensions.DirectionOf2D(new Vector2(delta.x, -delta.y)));
    }