Playable Character needs to hit AI character, but it's Left or Right dependent

Started by Olleh19, Wed 21/10/2020 03:03:33

Previous topic - Next topic

Olleh19

This is the code i have so far. The Punches are on View 5 (Left, for Left Punch) and Right (For Right Punch).  Those are just 1 frame each, so i have been looking for a synthax for that, Loop, Character. Frame, but i can't type it out "correctly".
I also would like the punch to not punch endlessly, if i hold the button. Cause that glitches the sprite, and the sound effect like crazy. (laugh)
It should be released, so player has to press again. a second a millisecond doesn't matter, aslong as it's not continuing the punch animation if holding the key.

Code: ags
function Player_NormalPunch()
{
 if (IsKeyPressed(eKeyZ) && cAxl.FaceCharacter(cEnemy1))
  {

 cEnemy1.Baseline=170;  //To avoid getting behind when smashing, or otherway around..
cAxl.ChangeView(5);         //He has one Loop with One frame Punch on the Leftside (Left) and Rightside (Right), 
 cAxl.SetIdleView(5, 0);    //That's why i try to do a abrupt idleview change, cause i thought perhaps that will "idle" according to his current direction. Does not work, it seems.
  Wait(5);

 while (cAxl.Animating) aEmptyPunch.Play();



 cAxl.UnlockView(eStopMoving);
 cAxl.ChangeView(2);

 Player_Punched_AI_Once=1;
 cEnemy1.Baseline=0;
 
  
 
 
  }

}   

Khris

Character.FaceCharacter()  is a function that changes the character's loop, it cannot be used to determine whether character A is currently facing character B.

To do that, you can simply compare coordinates and check loop numbers.

player.Loop == 1  means the player is facing left.
cEnemy1.x < player.x  means the enemy is further left on the screen, but they could be 1 pixel to the left and 100 pixels down, obviously.

Olleh19

Quote from: Khris on Wed 21/10/2020 09:21:02
Character.FaceCharacter()  is a function that changes the character's loop, it cannot be used to determine whether character A is currently facing character B.

To do that, you can simply compare coordinates and check loop numbers.

player.Loop == 1  means the player is facing left.
cEnemy1.x < player.x  means the enemy is further left on the screen, but they could be 1 pixel to the left and 100 pixels down, obviously.

After sleeping it doesn't even make sense to go for a facecharacter in his basic punch, it should have only been the Z button ofc. What was i thinking there.  (laugh). He did indeed change loop so he look at the right side, but it's not the right way to go, ofc.
I'll give it a go! Thanks as always Khris!

SMF spam blocked by CleanTalk