Hello,
I am setting up a simple enemy ai script using DoTween.
I have 4 trigger points on the enemy. Depending on which trigger is triggered the enemy will move and rotate a certain direction.
My question is when I have more than one IF statement in Update does it wait untill completion of a DOMove Sequence(after the enemy has moved to the designated position) to recheck if any of the other "IF" Statements are true. Or will Update check to see if any "If" statements are true even before the completion of the Sequenced DOMove designated position has been reached. My code is not final or tested and written for this question only so far.
My movement is similar to grid system movement as I want all end positions to land on an Interger so my concern would be that another If statement would interupt the completion of the enemies movement thus the new movment would begin too soon.
Sample Code:
void Update()
{
//forward
if (oneTrigger && twoTrigger.colliding)
Sequence mySequence = DOTween.Sequence();
mySequence.Append(transform.DOMove(new Vector3(1,0,0), 0.5f).SetRelative());
//Down
else if (!oneTrigger && !twoTrigger.colliding)
// Set the new target Rotation and new target Move
Sequence mySequence = DOTween.Sequence();
mySequence.Append(transform.DORotate(new Vector3(0,90,0), 1));
mySequence.Append(transform.DOMove(new Vector3(1,0,0), 0.5f).SetRelative());
//Turn
else if (oneTrigger && threeTrigger.colliding)
// Set the new target Rotation and new target Move
Sequence mySequence = DOTween.Sequence();
mySequence.Append(transform.DORotate(new Vector3(0,180,0), 1));
mySequence.Append(transform.DOMove(new Vector3(1,0,0), 0.5f).SetRelative());
{
As a safeguard againts moving to soon I might add something like this to see if the enemy is positioned on a Interger:
public int myX = (int)transform.position.x;
public int myZ = (int)transform.position.z;
void Update()
{
if (!oneTrigger && !twoTrigger.colliding && myX==int && myZ==int)
Sequence mySequence = DOTween.Sequence();
mySequence.Append(transform.DOMove(new Vector3(1,0,0), 0.5f).SetRelative());
//I am not sure if this add on of the Int would be necessary?
Thanks
R_Chevallier