Prevent enemies to move in X or Z axis?

Greetings, developers!

I'm trying to make a enemy that, by default, is not able to move on the Z axis during it's WALK and BACKWALK animations, and only move on the Z axis by using a dasher animationscript in certain moves. Hos can I make this kind of effect?
 
The only way I know is to lock enemy's position in certain x or z (depending on limited movement) with onmovexscript or onmovezscript, respectively.
When enemy is spawned, his/her starting x or z is stored in its entity variable. This stored value will later be used by onmovexscript or onmovezscript (respectively) to lock his/her position.
Example for only move in Z axis while WALKing or BACKWALKing:
First, store his starting x coordinate:
C:
anim    spawn
@script     
  if(frame==1){
    void self = getlocalvar("self");
    int x = getentityproperty(self,"x");

    setentityvar(self, 1, x);
  }
@end_script

then declare onmovexscript:
onmovexscript data/scripts/noX.c

with this:
C:
void main()
{
    void self = getlocalvar("self");
    int Tx = getentityvar(self, 1);

    if(Tx){
      changeentityproperty(self, "position", Tx);
    }
}

This works great if enemy doesn't move in x axis in any of his/her attacks such as moving turret/sentry.
 
Back
Top Bottom