Two Unit AI Issues

Place to get help with not working mods / modding interface.
Post Reply
User avatar
Reika
Filter Inserter
Filter Inserter
Posts: 582
Joined: Tue May 19, 2015 1:56 am
Contact:

Two Unit AI Issues

Post by Reika »

So I made a custom flying creature, spawned under special circumstances (and explicitly only through my control.lua). Whenever I spawn it, the creature is immediately directed to a predetermined target, using the following code:
https://github.com/ReikaKalseki/NauvisD ... lua#L1-L11

Yet these creatures often are not aggroing on the target at all - often wandering to some nearby object then idly waiting - or are easily getting "distracted" by the player or by turrets. I thought defines.none was supposed to explicitly prevent that. And it is not due to the target being destroyed; it happens even when I disabled the wall destruction.
(Related question: In cases where their target is destroyed, can I control how they select a new target?)

------

The second question is that these, being flying creatures (coded as collision_mask = { } in the entity prototype), are able to path through any obstacle and cross water. And indeed, ones spawned manually through the console (and resultantly aggroed on the player) do this just fine, as can be seen in this video:
https://www.youtube.com/watch?v=_w4Mexi ... e=youtu.be

However, the ones spawned with my control.lua are pathfinding as normal biters, i.e. around obstacles and avoiding water. This does not make sense for a flying creature, and more importantly, harms the intended system I have which requires they be something unable to be simply blocked by building some obstacles.
Image

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5151
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Two Unit AI Issues

Post by Klonan »

Reika wrote:So I made a custom flying creature, spawned under special circumstances (and explicitly only through my control.lua). Whenever I spawn it, the creature is immediately directed to a predetermined target, using the following code:
https://github.com/ReikaKalseki/NauvisD ... lua#L1-L11

Yet these creatures often are not aggroing on the target at all - often wandering to some nearby object then idly waiting - or are easily getting "distracted" by the player or by turrets. I thought defines.none was supposed to explicitly prevent that. And it is not due to the target being destroyed; it happens even when I disabled the wall destruction.
(Related question: In cases where their target is destroyed, can I control how they select a new target?)
This is because the units are part of a unit group, which is not currently ideal for attacking targets. You will have better luck using groups only for movement right now (Though I hope there will be some improvements for 0.17)

And the distraction issue is also due to them being in a unit group, the individual biters have a 'follow group' command, with their own distraction. In 0.17 we added an option for these group biters to use the groups current commands distraction, so biters in a group will correctly follow the groups 'none' distraction.
Reika wrote: The second question is that these, being flying creatures (coded as collision_mask = { } in the entity prototype), are able to path through any obstacle and cross water. And indeed, ones spawned manually through the console (and resultantly aggroed on the player) do this just fine, as can be seen in this video:
https://www.youtube.com/watch?v=_w4Mexi ... e=youtu.be

However, the ones spawned with my control.lua are pathfinding as normal biters, i.e. around obstacles and avoiding water. This does not make sense for a flying creature, and more importantly, harms the intended system I have which requires they be something unable to be simply blocked by building some obstacles.
Yep, once again this is because they are in a group. The groups are given a default collision mask for pathfinding, and don't use the collision mask of their members.

In short, all the problems are due to using UnitGroups. I would recommend just setting commands on the units directly until we have made some further improvements

User avatar
Reika
Filter Inserter
Filter Inserter
Posts: 582
Joined: Tue May 19, 2015 1:56 am
Contact:

Re: Two Unit AI Issues

Post by Reika »

Klonan wrote:
Reika wrote:So I made a custom flying creature, spawned under special circumstances (and explicitly only through my control.lua). Whenever I spawn it, the creature is immediately directed to a predetermined target, using the following code:
https://github.com/ReikaKalseki/NauvisD ... lua#L1-L11

Yet these creatures often are not aggroing on the target at all - often wandering to some nearby object then idly waiting - or are easily getting "distracted" by the player or by turrets. I thought defines.none was supposed to explicitly prevent that. And it is not due to the target being destroyed; it happens even when I disabled the wall destruction.
(Related question: In cases where their target is destroyed, can I control how they select a new target?)
This is because the units are part of a unit group, which is not currently ideal for attacking targets. You will have better luck using groups only for movement right now (Though I hope there will be some improvements for 0.17)

And the distraction issue is also due to them being in a unit group, the individual biters have a 'follow group' command, with their own distraction. In 0.17 we added an option for these group biters to use the groups current commands distraction, so biters in a group will correctly follow the groups 'none' distraction.
Reika wrote: The second question is that these, being flying creatures (coded as collision_mask = { } in the entity prototype), are able to path through any obstacle and cross water. And indeed, ones spawned manually through the console (and resultantly aggroed on the player) do this just fine, as can be seen in this video:
https://www.youtube.com/watch?v=_w4Mexi ... e=youtu.be

However, the ones spawned with my control.lua are pathfinding as normal biters, i.e. around obstacles and avoiding water. This does not make sense for a flying creature, and more importantly, harms the intended system I have which requires they be something unable to be simply blocked by building some obstacles.
Yep, once again this is because they are in a group. The groups are given a default collision mask for pathfinding, and don't use the collision mask of their members.

In short, all the problems are due to using UnitGroups. I would recommend just setting commands on the units directly until we have made some further improvements
This is a much more optimistic answer than I was expecting! I was not aware you could set commands to individual entities (is that new?); I will try that shortly. :D

One question remains unanswered though: If I tell nuker A to destroy wall X, and then nuker B destroys wall X before A reaches X, what happens to A? Is there a hook I can use to give A a new target (or, failing that, destroy it)?
Image

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5151
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Two Unit AI Issues

Post by Klonan »

Reika wrote:One question remains unanswered though: If I tell nuker A to destroy wall X, and then nuker B destroys wall X before A reaches X, what happens to A? Is there a hook I can use to give A a new target (or, failing that, destroy it)?
In 0.17, we added a new event:

Code: Select all

on_ai_command_completed

Called when a unit/group completes a command.

Contains
unit_number :: uint: unit_number/group_number of the unit/group which just completed a command.
result :: defines.behavior_result
So you will be able to do much greater things

User avatar
Reika
Filter Inserter
Filter Inserter
Posts: 582
Joined: Tue May 19, 2015 1:56 am
Contact:

Re: Two Unit AI Issues

Post by Reika »

Klonan wrote:
Reika wrote:One question remains unanswered though: If I tell nuker A to destroy wall X, and then nuker B destroys wall X before A reaches X, what happens to A? Is there a hook I can use to give A a new target (or, failing that, destroy it)?
In 0.17, we added a new event:

Code: Select all

on_ai_command_completed

Called when a unit/group completes a command.

Contains
unit_number :: uint: unit_number/group_number of the unit/group which just completed a command.
result :: defines.behavior_result
So you will be able to do much greater things
*grins in excitement* :D
Image

kyranzor
Filter Inserter
Filter Inserter
Posts: 499
Joined: Fri Oct 31, 2014 4:52 pm
Contact:

Re: Two Unit AI Issues

Post by kyranzor »

Very exciting, thanks for all your work on this stuff Klonan

Post Reply

Return to “Modding help”