Posted by Jadeeye
in How to make AI trigger when the opponent attack them from behind (Started by Jadeeye August 19, 2022, 09:07:36 am
Board: M.U.G.E.N Development Help
Board: M.U.G.E.N Development Help
Working un Yun&Yang I kinda had trouble with stuff similar to this.It works like a charm, that's exactly what I need. Thank you.
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.
Thank you for your clear explanation.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.
1/ Yea, I forgot the statetype != A
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