YesNoOk
avatar

How to make AI trigger when the opponent attack them from behind (Read 8203 times)

Started by Jadeeye, August 19, 2022, 09:07:36 am
Share this topic:
How to make AI trigger when the opponent attack them from behind
#1  August 19, 2022, 09:07:36 am
  • ***
  • KATO KATO KATO KATO KATOOOOOOOOO......!!!!
Hi guys,

I want to make AI jump when some opponent shoot them in Simul Mode (2vs2). The code works but the AI also jump even they stand behind an opponent. Here's my code.

Code:
[State -1, Jump]
type = ChangeState
value = 40
triggerall = AILevel && numenemy && roundstate = 2 && movetype != H
triggerall = (enemy, name = "Cyclop") && (enemy, stateno = 1000)
triggerall = ctrl
;Both chars are facing each other
trigger1 = (facing = 1 && (enemy, facing = -1)) || (facing = -1 && (enemy, facing = 1))
;Both chars are facing the same direction but the opponent must stand behind the main char
trigger2 = facing = 1 && (enemy, facing = 1) && backedgebodydist > (enemy, backedgebodydist >= 0)
trigger3 = facing = -1 && (enemy, facing = -1) && backedgebodydist > (enemy, backedgebodydist >= 0)

I just want the AI jump when face to face the opponent or the opponent stand behind them, not they stand behind the opponent.
Last Edit: August 20, 2022, 03:51:30 am by Jadeeye
Re: How to make AI trigger when the opponent attack them from behind
#2  August 19, 2022, 02:02:12 pm
  • **
    • Ukraine
AS far as I am concerned, when an opponent is behind you, p2bodydist X starts giving negative numbers. I would try testing that, like
p2bdoydist x < -20 or less.
But do not take -10 or -5 as values, p2bodydist x can give those when both of you are standing close to each other.
Re: How to make AI trigger when the opponent attack them from behind
#3  August 19, 2022, 03:26:30 pm
  • **
  • Super Gamers
  • Twins who play games.
    • Brazil
    • sites.google.com/view/gemeos-dos-jogos
Hello how are you? try using:
enemy(0), facing != facing
enemy(1), facing != facing

enemy(0) is Player 2 and enemy(1) is Player 4.

We hope to have helped.

Re: How to make AI trigger when the opponent attack them from behind
#4  August 19, 2022, 04:00:44 pm
  • ***
  • KATO KATO KATO KATO KATOOOOOOOOO......!!!!
AS far as I am concerned, when an opponent is behind you, p2bodydist X starts giving negative numbers. I would try testing that, like
p2bdoydist x < -20 or less.
But do not take -10 or -5 as values, p2bodydist x can give those when both of you are standing close to each other.
Hello how are you? try using:
enemy(0), facing != facing
enemy(1), facing != facing

enemy(0) is Player 2 and enemy(1) is Player 4.

We hope to have helped.

Thank guys, both method didn't work as intend. As your codes, the AI will trigger when face to face the opponent but it won't trigger when standing in front or behind the opponent (AI and their opponent are facing the same direction).

I used this code to let AI know the opponent stand behind them.

Code:
trigger2 = facing = 1 && (enemy, facing = 1) && backedgebodydist > (enemy, backedgebodydist >= 0) 
trigger3 = facing = -1 && (enemy, facing = -1) && backedgebodydist > (enemy, backedgebodydist >= 0)

It means that in the same direction, the distance from the AI's back to the edge of the screen is greater than the distance from the opponent's back to the edge of the screen. This shows that the opponent is standing behind the AI. But it didn't work.
Last Edit: August 19, 2022, 04:04:25 pm by Jadeeye
Re: How to make AI trigger when the opponent attack them from behind
#5  August 19, 2022, 04:15:51 pm
  • ***
  • 하나뿐인 한국인 대표
  • Ambassador of MugenRevival
    • South Korea
    • sites.google.com/view/kolossoni-mugen
Simul mode is hard to code.
But I think you would need to calculate the distance instead of using facing = -1
Re: How to make AI trigger when the opponent attack them from behind
#6  August 19, 2022, 04:28:04 pm
  • ***
  • KATO KATO KATO KATO KATOOOOOOOOO......!!!!
Simul mode is hard to code.
But I think you would need to calculate the distance instead of using facing = -1
Could you let me know how to calculate it?

I think the key of the problem here is the distance from the back of AI and opponent to the edge of the screen but I don't know how to code a comparison between them to make the AI trigger.
Re: How to make AI trigger when the opponent attack them from behind
#7  August 19, 2022, 08:10:46 pm
  • *****
  • Shame on you!
    • USA
Working un Yun&Yang I kinda had trouble with stuff similar to this.
This might help a tiny bit https://mugenguild.com/forum/msg.2177655
https://mugenguild.com/forum/topics/facing-triggers-169645.0.html Facing can be confusing too.

But I think a major issue could be
enemy,
You might want to find a way to make that a bit more solid. Use DisplayToClipboard and make sure it's always the value you want. It might be tough to make happen. But I have a feeling it's changing on you and you dont want it to.

Also
enemy(1), facing = facing
Should be when the 2 chars are facing the same direction. Aka one is behind the other. But the idea is correct.

(enemy, backedgebodydist >= 0)  this is basically a true or false.
(backedgebodydist > enemy, backedgebodydist )
Should be closer to what you want.
vVv Ryuko718 Updated 10/31/22 vVv
Re: How to make AI trigger when the opponent attack them from behind
#8  August 20, 2022, 02:58:00 am
  • **
Code:
[State -1, Jump]
type = ChangeState
value = 40
triggerall = AILevel && numenemy && roundstate = 2 && movetype != H
triggerall = (enemy, name = "Cyclop") && (enemy, stateno = 1000)
triggerall = ctrl
;Both chars are facing each other
trigger1 = (facing = 1 && (enemy, facing = -1)) || (facing = -1 && (enemy, facing = 1))
;Both chars are facing the same direction but the opponent must stand behind the main char
trigger2 = facing = 1 && (enemy, facing = 1) && backedgebodydist > (enemy, backedgebodydist >= 0)
trigger3 = facing = -1 && (enemy, facing = -1) && backedgebodydist > (enemy, backedgebodydist >= 0)

Firstly, you should have a triggerall=statetype!=A unless you don't have control in the air.  Also if you set ctrl, then you don't need movetype!=H.

Secondly, it is as Odb718 says. (enemy,backedgebodydist>=0) is a boolean and in this case is =1.  It's no different than saying backedgebodydist >1 when the enemy exists.  These triggers will always return true so your character will always jump regardless of whether they are in front or behind cyclop.

Thirdly, using enemy as a trigger redirect will only trigger if the first enemy is cyclop. If he becomes the second enemy, then the whole code won't trigger and if the enemy team consists of 2 cyclops then the code will only work against the first one, not the second.

If you're using enemy(0) and enemy(1), then you'd have to use teammode=simul as well else you're gonna get debug floods against single enemies.  This means it'd be easier if you have two separate jump changestates, one for vs single enemy and the other for vs simultaneous enemy.
Using these 2 redirects will also result in the code being more complicated.
As an example, the code for only when 'facing right' becomes:

Code:
trigger1 = facing=1 && ((enemy(0),name="cylcop" && enemy(0),facing=-1 && enemy(0),stateno=1000) || (enemy(1),name="cyclop" && enemy(1),facing=-1 && enemy(1),stateno=1000))
trigger2 = facing=1 && (enemy(0),name="cyclop" && enemy(0),facing=1 && enemy(0),stateno=1000 && ((enemy(0),backedgedist)<backedgedist))
trigger3 = facing=1 && (enemy(1),name="cyclop" && enemy(1),facing=1 && enemy(1),stateno=1000 && ((enemy(1),backedgedist)<backedgedist))

You should also factor in the fact that jumps are hardcoded into the AI so they will randomly jump unless you code them not to in state 40 or the negative states.  If you don't it will lead to false positives from time to time even if your whole code is correct.
Last Edit: August 20, 2022, 03:03:43 am by SteelHammers
Re: How to make AI trigger when the opponent attack them from behind
New #9  August 20, 2022, 03:51:09 am
  • ***
  • KATO KATO KATO KATO KATOOOOOOOOO......!!!!
Working un Yun&Yang I kinda had trouble with stuff similar to this.
This might help a tiny bit https://mugenguild.com/forum/msg.2177655
https://mugenguild.com/forum/topics/facing-triggers-169645.0.html Facing can be confusing too.

But I think a major issue could be
enemy,
You might want to find a way to make that a bit more solid. Use DisplayToClipboard and make sure it's always the value you want. It might be tough to make happen. But I have a feeling it's changing on you and you dont want it to.

Also
enemy(1), facing = facing
Should be when the 2 chars are facing the same direction. Aka one is behind the other. But the idea is correct.

(enemy, backedgebodydist >= 0)  this is basically a true or false.
(backedgebodydist > enemy, backedgebodydist )
Should be closer to what you want.
It works like a charm, that's exactly what I need. Thank you.

Code:
[State -1, Jump]
type = ChangeState
value = 40
triggerall = AILevel && numenemy && roundstate = 2 && movetype != H
triggerall = (enemy, name = "Cyclop") && (enemy, stateno = 1000)
triggerall = ctrl
;Both chars are facing each other
trigger1 = (facing = 1 && (enemy, facing = -1)) || (facing = -1 && (enemy, facing = 1))
;Both chars are facing the same direction but the opponent must stand behind the main char
trigger2 = facing = 1 && (enemy, facing = 1) && backedgebodydist > (enemy, backedgebodydist >= 0)
trigger3 = facing = -1 && (enemy, facing = -1) && backedgebodydist > (enemy, backedgebodydist >= 0)

Firstly, you should have a triggerall=statetype!=A unless you don't have control in the air.  Also if you set ctrl, then you don't need movetype!=H.

Secondly, it is as Odb718 says. (enemy,backedgebodydist>=0) is a boolean and in this case is =1.  It's no different than saying backedgebodydist >1 when the enemy exists.  These triggers will always return true so your character will always jump regardless of whether they are in front or behind cyclop.

Thirdly, using enemy as a trigger redirect will only trigger if the first enemy is cyclop. If he becomes the second enemy, then the whole code won't trigger and if the enemy team consists of 2 cyclops then the code will only work against the first one, not the second.

If you're using enemy(0) and enemy(1), then you'd have to use teammode=simul as well else you're gonna get debug floods against single enemies.  This means it'd be easier if you have two separate jump changestates, one for vs single enemy and the other for vs simultaneous enemy.
Using these 2 redirects will also result in the code being more complicated.
As an example, the code for only when 'facing right' becomes:

Code:
trigger1 = facing=1 && ((enemy(0),name="cylcop" && enemy(0),facing=-1 && enemy(0),stateno=1000) || (enemy(1),name="cyclop" && enemy(1),facing=-1 && enemy(1),stateno=1000))
trigger2 = facing=1 && (enemy(0),name="cyclop" && enemy(0),facing=1 && enemy(0),stateno=1000 && ((enemy(0),backedgedist)<backedgedist))
trigger3 = facing=1 && (enemy(1),name="cyclop" && enemy(1),facing=1 && enemy(1),stateno=1000 && ((enemy(1),backedgedist)<backedgedist))

You should also factor in the fact that jumps are hardcoded into the AI so they will randomly jump unless you code them not to in state 40 or the negative states.  If you don't it will lead to false positives from time to time even if your whole code is correct.

Thank you for your clear explanation.

1/ Yea, I forgot the statetype != A :P

3/ Actually, I coded for second enemy too. I also made my own jumping with neutral jump only. My codes above is just an example.

The codes below should work for two opponents in Simul Mode. By using facing, frontedgebodydist and backedgebodydist, the AI only trigger when face to face the opponent (trigger1, trigger2) or the opponent stand behind them (trigger3, trigger4).
Code:
[State -1, Jump]
type = ChangeState
value = 40
triggerall = AILevel && numenemy && roundstate = 2 && statetype != A
triggerall = (enemy, name = "Cyclop") && (enemy, stateno = 1000)
triggerall = ctrl
trigger1 = facing = 1 && (enemy, facing = -1) && (frontedgebodydist > enemy, backedgebodydist)
trigger2 = facing = -1 && (enemy, facing = 1) && (frontedgebodydist > enemy, backedgebodydist)
trigger3 = facing = 1 && (enemy, facing = 1) && (backedgebodydist > enemy, backedgebodydist)
trigger4 = facing = -1 && (enemy, facing = -1) && (backedgebodydist > enemy, backedgebodydist)

[State -1, Jump]
type = ChangeState
value = 40
triggerall = AILevel && numenemy && roundstate = 2 && statetype != A
triggerall = (enemy(numenemy = 2), name = "Cyclop") && (enemy(numenemy = 2), stateno = 1000)
triggerall = ctrl
trigger1 = facing = 1 && (enemy(numenemy = 2), facing = -1) && (frontedgebodydist > enemy(numenemy = 2), backedgebodydist)
trigger2 = facing = -1 && (enemy(numenemy = 2), facing = 1) && (frontedgebodydist > enemy(numenemy = 2), backedgebodydist)
trigger3 = facing = 1 && (enemy(numenemy = 2), facing = 1) && (backedgebodydist > enemy(numenemy = 2), backedgebodydist)
trigger4 = facing = -1 && (enemy(numenemy = 2), facing = -1) && (backedgebodydist > enemy(numenemy = 2), backedgebodydist)

------------------------------------------------------------------------------------------------------

Once again, thank guys so much. I learned many things from this topic. Happy coding :lugoi:
Last Edit: August 20, 2022, 04:04:41 am by Jadeeye