Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access to local targets from sensors #36

Closed
simeonradivoev opened this issue May 28, 2023 · 8 comments
Closed

Access to local targets from sensors #36

simeonradivoev opened this issue May 28, 2023 · 8 comments

Comments

@simeonradivoev
Copy link

Is there a way to access other targets from a target sensor?
Let's say you need to choose a target based on another target.

@crashkonijn
Copy link
Owner

Hey @simeonradivoev, thanks for checking out this package!

I don't think it's possible to access other targets. That would probably require sensors to have an order/dependancy on each other, which they don't have right now.

Perhaps you can abstract the gathering of targets to a class which overlaps multiple sensors?

@simeonradivoev
Copy link
Author

I just went with storing a target to a component and an action that finds a target. But I'm having another issues.
image
Thus runs, but keeps repeating the Reload action. Not sure why, are we supposed to add a check for each action or it will run indefinitely?

@crashkonijn
Copy link
Owner

Can you show the code for the reload action?

@simeonradivoev
Copy link
Author

simeonradivoev commented May 29, 2023

public class ReloadAction : ActionBase<ReloadAction.Data>
    {
        #region Overrides of ActionBase

        public override void Created()
        {
        }

        #endregion

        #region Overrides of ActionBase<Data>

        public override void Start(IMonoAgent agent, Data data)
        {
            data.Timer = 2;
        }

        public override ActionRunState Perform(IMonoAgent agent, Data data, CrashKonijn.Goap.Classes.ActionContext context)
        {
            data.Timer -= context.DeltaTime;

            if (data.Timer > 0)
            {
                return ActionRunState.Continue;
            }

            data.Stats.Ammo = data.Stats.MaxAmmo;

            return ActionRunState.Stop;
        }

        public override void End(IMonoAgent agent, Data data)
        {
        }

        #endregion

        public class Data : IActionData
        {
            public float Timer { get; set; }

            [GetComponent]
            public StatsComponent Stats { get; set; }

            #region Implementation of IActionData

            public ITarget Target { get; set; }

            #endregion
        }
    }

If I explicitly add the condition that ammo needs to be lower or equal to 0, Then it skips it. But shouldn't it do that without specifying it?

@crashkonijn
Copy link
Owner

crashkonijn commented May 29, 2023

It should, yes. I think this might be a bug.

I don't have my laptop with me today, I'll look into it tomorrow!

Thanks for the report!

@crashkonijn
Copy link
Owner

Update; I have created a unit test that fails. I'm working on the fix as we speak!

@crashkonijn
Copy link
Owner

Hello @simeonradivoev,

Could you confirm my PR fixes your issues?

If you change the git url to this you can directly reference the branch:

https://github.com/crashkonijn/GOAP.git?path=/Package#fix/resolver-planning-action-for-satisfied-condition

@simeonradivoev
Copy link
Author

Yea, it works now. Thx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants