/// <summary>
    /// Generate a force in the current position of the prop
    /// </summary>
    /// <param name="pf"></param>
    public void GenerateForce(ref PotentialFieldScriptableObject pf)
    {
        int pX = pf.LocalPosX(transform.position);
        int pY = pf.LocalPosY(transform.position);

        pf.AddLinearForce(pX, pY, force, rad);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Choose the next tile to go to.
    /// </summary>
    protected void FindNextPos()
    {
        int bestDir = -1;
        int bestVal = 0;
        PotentialFieldScriptableObject pf = LevelManager.GetInstance().GetResultPF();
        int        pX        = pf.LocalPosX(transform.position);
        int        pY        = pf.LocalPosY(transform.position);
        Vector2Int newTarget = new Vector2Int(0, 0);

        if (pf.GetCellValue(pX, pY - 1) > bestVal)
        {
            bestVal     = pf.GetCellValue(pX, pY - 1);
            bestDir     = 0;
            newTarget.x = 0;
            newTarget.y = -1;
        }
        if (pf.GetCellValue(pX - 1, pY) > bestVal)
        {
            bestVal     = pf.GetCellValue(pX - 1, pY);
            bestDir     = 1;
            newTarget.x = -1;
            newTarget.y = 0;
        }
        if (pf.GetCellValue(pX, pY + 1) > bestVal)
        {
            bestVal     = pf.GetCellValue(pX, pY + 1);
            bestDir     = 2;
            newTarget.x = 0;
            newTarget.y = 1;
        }
        if (pf.GetCellValue(pX + 1, pY) > bestVal)
        {
            bestVal     = pf.GetCellValue(pX + 1, pY);
            bestDir     = 3;
            newTarget.x = 1;
            newTarget.y = 0;
        }

        if (bestDir != -1)
        {
            findNewTargetPos  = false;
            targetPos         = newTarget;
            remainingDistance = new Vector3(targetPos.x, 0, -targetPos.y);
            //Debug.Log("Target pos: " + targetPos.x + " " + targetPos.y);
        }
    }
Ejemplo n.º 3
0
 /// <summary>
 /// Affect the referenced potential field with a force.
 /// Adds a small weight to the current position to avoid enemies colliding into eachother paths.
 /// </summary>
 /// <param name="pf">The potential field to affect.</param>
 public new void GenerateForce(ref PotentialFieldScriptableObject pf)
 {
     pf.AddCellValue(pf.LocalPosX(transform.position), pf.LocalPosY(transform.position), 2);
 }