Movement point system

So I went for a Movement point system where the idea was to deactivate the movement script and activate options like combat later (used the spin for it now).

ezgif.com-video-to-gif

It kinda works. But it doesn’t update propperly and only when I manually reselect the unit. Not sure how to deal with this, thinking my script should be okey. I’ll place the full implimentation down here, and yes I could prob clean it up more and want to redo the enable and disable at some points when there will be more but 1 problem at a time :stuck_out_tongue:

    private int MovementAmount()
    {
        GridPosition targetGridPosition = LevelGrid.Instance.GetGridPosition(targetPosition);
        GridPosition unitGridPosition = LevelGrid.Instance.GetGridPosition(transform.position);

        GridPosition moveGridDistance = (targetGridPosition - unitGridPosition);

        int movementAmount = Mathf.Abs(moveGridDistance.x) + Mathf.Abs(moveGridDistance.z);

        return movementAmount;
    }


    private void NoMovementCheck()
    {
        maxMoveDistance = maxMoveDistance - distanceMoved;

        if(maxMoveDistance <= 0 )
            {
                gameObject.GetComponent<MoveAction>().enabled = false;
                gameObject.GetComponent<SpinAction>().enabled = true;
            }

    }

    public int GetMovementLeft()
    {
        movementLeft = maxMoveDistance - totalDistanceMoved;
        return movementLeft;
    }
    public override void TakeAction(GridPosition gridPosition, Action onActionComplete)
    {
        this.onActionComplete = onActionComplete;
        isActive = true;
        this.targetPosition = LevelGrid.Instance.GetWorldPosition(gridPosition);
        distanceMoved =  MovementAmount();
        totalDistanceMoved += MovementAmount();
    }

This is the base idea behind it

        if (Vector3.Distance(targetPosition, transform.position) > stoppingDistance)
            {
                transform.position += moveDirection * Time.deltaTime * moveSpeed;

                unitAnimator.SetBool("IsWalking", true);
            }
        else
            {
                unitAnimator.SetBool("IsWalking", false);
                isActive = false;
                onActionComplete();
                NoMovementCheck();
            }

I am atm checking for it at the end of my movement, but I could move that to onActionComplete at some point to make it cleaner.

When I check for the value in the UnitActionSystem under Update it only gives me the set starting value

    private void NoMovementCheck()
    {
        Debug.Log(movementLeft);
        if(movementLeft <= 0)
            {                         
                OnNoMovement?.Invoke(this, EventArgs.Empty);           
            }
    }
        moveAction = selectedUnit.GetMoveAction();
        movementLeft = moveAction.GetMovementLeft();

So the debug keeps giving me the same number what means it doesn’t send to the UI to update the bottons. But i don’t see why it won’t.

There are no error messages or anything to help me out seeing what I do wrong.

any pointers are welcome ^^

So you want to first spend all the movement points and only then show the Attack actions?
I’m not sure where you are setting the movementLeft. Are you calling NoMovementCheck(); on Update? You should probably be firing the OnNoMovement event on the onActionComplete rather than on Update.
That’s probably what’s causing the issue, you’re probably updating the UI on OnNoMovement and triggering that before the OnActionComplete, there’s a slight delay in your video.

2 Likes

Yes, forced to move before some other actions.

And that was indeed set up in Update.

played around with it a little bit and changed the onActionComplete function so now it can contain a list and makes it actually easier later to activate the movement back up. But I don’t know if keep checking for these kind of things with ALL actions can be a problem down the line.

    private void AfterAction()
    {
        moveAction = selectedUnit.GetComponent<MoveAction>();

        ClearBusy();

        NoMovementCheck();
    }

At first it was being weird with what unit and move Action it had to use but declairing it in here itself seemed to work. I feel like i’ve done it “Wrong” but it’s working how i want to so i call that a win.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms