Hello I am trying to use move ai in 2d sideview game.
But it works somewhat differently than I expected.
I have been collecting questions I have been wondering for two weeks.

1. My custom move ai code is as follows.

void update() {
PlayerMove(direction.x);
}
public void SetDestination (Vector3 goal) {
Debug.Log("setdestination");
direction = goal.x> transform.position.x? Vector2.right: Vector2.left;
}
public void Stop () {
Debug.Log("stop");
direction = Vector2.zero;
}
// Determine the left/right direction by comparing the target's coordinates with the user's position.


1. The move ai was configured as custom through the code above. However, the problem is that the SetDestination and Stop functions are executed simultaneously.
I can't understand how the orc's moveai works.
As in the screenshot,
If an enemy is detected, the target is accessed through many setdestination functions. After that, when the attack ability is executed, the stop function seems to be called.
View post on imgur.com
The problem is that after the stop function setdestination is called together. So, if setdestination is executed through the above code, the character stops after moving a little through the update function.

Through this process, the character moves little by little during each attack and eventually results in overlap.

I tried using auto stop function of move ai setting,
After stopping after a certain distance, it was confirmed that setdestination (via log) is called again.
If stopped, why is it calling setdestination again?

In summary, the update function is executed every frame.
In the case of Orc, the set destination function and the stop function are executed at the same time, so the character moves a little after the attack, then moves again after the attack, and eventually the situation completely overlaps with my character.
Why is that?

2. My game is a 2d side view game.
How to set the movement detection angle for 2d side view? (In the tutorial, 180 degrees is 90 degrees for right/left respectively, but I don't know how to set the angle in a left/right side scrolling game. Is there a way to distinguish right/left?)

3. After auto stop, set destination is called again.
As mentioned in No. 1, when I ran it through my code above, as soon as auto stop, the set destination is executed and the character moves stuttering.
Is there a way to stop completely after auto stop? Do I need to edit my code?


4. What does the minimum distance for target position check mean?
check 0 / interval 0.2 / minimum distance 2
check 1 / interval 0.5 / minimum distance 5
check 2 / interval 1 / minimum distance 10
If it is set as above, is check2 triggered when the minimum distance is greater than 10?
Or is check2 triggered when the minimum distance is between 5 and 10?
And, is the setdestination function called every time the check is made?


5. Why can't players (leaders) use ai?
(The reason we need a player using move ai,ai (no input required),
My mobile game is an RPG- game where ai players automatically hunt monsters, which is adopted in many mobile games)
I searched in the forum, but it seems that the movement through HIDDEN members and game events is not the way I want.
Why can't players use AI?

6. Is index 0 of each group array serving as a leader? (That is, whether the leader of the player group should be index 0..)

7. How to change the leader of the player group or combat group (all individual groups)

8. Does the ai controlled option in the combatant settings need not be set in enemy combatants?
Is this setting an option specific to the player?


9. I want to know the relationship of each move Ai range.
Real-Time Battle Settings-MoveAi Range 15
Move AI EnemyDetection Base Detection Range-10
MoveDetection 0 type:Sight Range-5

If it is set as above, what range is applied?
Should all be set to the same number??

Or is the range of the battle system the maximum limit and cannot exceed it?
  • 1) Might be an issue with your move AI's setup - generally, the stop function is called only when needed, e.g. when the combatant comes within the stop range when hunting (if used).

    2) First of all, use the XY horizontal plane in your move detections. The center of the angle is at the game object's forward direction, e.g. if that's not the actual forward facing direction of your game object, you can adjust that with the Angle Offset.

    3) Probably like #1 an issue with your overall setup. It sounds like you're not using Threshold in your ranges, which can lead to hard stop-go changes instead of stopping and waiting for a bit until the range checks out again.

    4) These settings handle how often the movement position is updated when following a target, so the minimum distance defines when to use that interval.
    E.g. in your setup, when the target is 12 world units away, it'll use 1 second interval, when it's 6 away, it'll use 0.5 seconds.

    Also, it's best to have a 0 second 0 distance interval as your first check to update the position each frame when being close by. You can also just use that as your only check - these settings are mainly for performance optimization. E.g. depending on the number of active combatants using move AI and the used movement component updates each frame could impact performance, while others might not have much impact at all.

    5) You can have the player being controlled by the battle AI if you enable AI Controlled and AI Controlled Player in the combatant's Battle Settings > AI Settings.
    Move AI on the other hand can't be used by the player - as ORK assumes the player is, well, controlled by the player and uses a movement component to move him around. You could try using a hidden non-battle player, so all your battle members are move AI controlled. This can be done by using a Leave Battle Group and Hide Member node after joining your first combatant (player) to the player group.

    6) Yes, basically the first combatant joining the player group is the player (but can be changed). There's also a separation between field leader and battle leader, e.g. if the player isn't part of the battle group.

    7) You can use a Set Player node in events, a Group menu part in menu screens for managing your group, using the Group Member Keys (Base/Control > Game Controls) or via scripting:
    ORK.Game.PlayerHandler.SetPlayer(newPlayer, false);

    8) Non-player group combatants (e.g. enemies) are always AI controlled.
    Enabling AI Controlled will have members of the player group be AI controlled, except the player.
    Enabling AI Controlled Player will also have the player AI controlled.

    9) The Move AI Range defines the distance to the player at which combatants can use the move AI. E.g. if you're using large areas with far away enemies, you might not want them to waste performance by moving around, so you can prevent them from doing that. You can also completely disable that range and have unlimited move AI range.
    You should probably use a higher move AI range than 15 if your detection range is 10. Try something like 50-100, or even disable it alltogether.

    The Base Detection Range defines the range in which combatants can detect possible targets and is the upper limit for any move detection of that move AI. It's basically there to collect all combatants within that range for further processing through the move detections.

    The move detection's range defines the range for that one move detection, e.g. Sight range 5 can detect any combatant within 5 world units by simply seing them (i.e. the combatant being within the detection angle and optionally using a raycast to check if something is in the way).
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • edited July 20
    Thank you for answer. Most have been solved :)

    1)Is this not an ork issue, is it working well??

    1.The status of the move component when approaching an enemy after detecting the enemy. It is set properly.
    View post on imgur.com
    2.Many setDestination functions are executed when moving to the enemy, and
    The stop function was executed when the attack ability was executed because an enemy exists within the scope of the base attack.
    (Clear Target is executed as shown in the screenshot. Is this correct?)
    View post on imgur.com
    3.As soon as the stop function is executed, the state of the move component..
    The player and the enemy are still fighting, but the target object part has disappeared and the mode is changed to idle. (Isn't the hunt state correct?)
    View post on imgur.com
    4.And before the attack ability is executed, the stop function and setDestination function are executed at the same time, and it seems that the source of the setdestination function is endturn. My game uses real time (as in the screenshot), but is it correct that these functions related to endturn are executed?
    View post on imgur.com

    2) I am using your xy plane. In this case, is the orc able to detect the player's front direction? (Positive x direction, i.e. right)
    (That is, when the angle is set to 90 degrees, is it correct to indicate the direction from the top to the right? in platformer)

    9) Does the player own the range? Or is it a combatant (enemy)?
    (That is, when the enemy approaches the player's defined move ai range, or when the player approaches the enemy's defined move ai range?)
    Post edited by KESHYAS on
  • 1) Could you post your move AI's setup?
    When just while moving it'll regularly stop and go, it's usually a setup issue, e.g. not using thresholds or bad stop range setup, etc.

    2) Hm, I'm not 100% sure here, so probably best to just try it.
    Alternatively, you can also use combatant triggers (learn more in the move AI how-to), where you can place them on your combatants as you need them.

    9) Move AI range and real time battle range are from the player, i.e. combatants outside that range can't use move AI or take part in real time battles.
    The move AI's range definitions are from the combatant, e.g. the detection ranges detect combatants in range of the user.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • edited August 3
    Thank you for answer! But one more question about move ai setup.

    1) This is my move ai setup. The custom code is at the top of the question.
    As you said here, how do I change the settings to prevent a hard stop/go?? (I don't know where the threshold is.)
    View post on imgur.com
    View post on imgur.com
    View post on imgur.com
    View post on imgur.com
    View post on imgur.com

    When the character stops through the stop function, setDestination is executed at the same time, and the character moves a little.
    (i.e SetDestination()> Update()> Stop() is executed in this order. As a result, move the character a little in update-it should not be moved...)

    The same is true for the autoStop function. At a certain distance, stop and setdestination are executed simultaneously.

    When the stop function is executed, it seems that clearTarget is also executed.
    Therefore, the target is missing from the targetObject in the monster's inspector.
    Post edited by KESHYAS on
  • Hm, the setup looks ok to me ...
    Could you send me a small Unity test project with your setup to check out? It'll be easier figuring out what's going on :)
    Send it (or a download link) to contact@orkframework.com.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
Sign In or Register to comment.