Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Technocrat on Thu 21/07/2011 16:42:53

Title: Player unable to walk when using "looking around" function...
Post by: Technocrat on Thu 21/07/2011 16:42:53
So, I've created a function designed to make the protagonist, Nancy, look around when she's standing still. So far, so good, she does look to the left when the cursor's on the left of the screen, and right when right, but now she refuses to walk anywhere when I click. I have a suspicion it's to do with the animating, but I'm not sure how I break her out of it to get her moving.


function Nancy_Gaze() {
 
  if(player.Animating == false){
   // Determine what direction Nancy is facing
   
   int FacingDir = player.Loop;
   int Neomousex = mouse.x + GetViewportX(); // Helps determine the real mouse.x in a scrolling room

   
   if (FacingDir==0){
     if((Neomousex - player.x < 30) && (Neomousex - player.x > -30)){player.UnlockView();return;} // Mouse too close to char
     if(Neomousex - player.x > 30){player.LockViewFrame(6, 0, 2);return;} // Look right
     if(Neomousex - player.x < -30){player.LockViewFrame(6, 0, 1);return;} // Look left
     
   }   
  } 
}



Thus far, I've only done it for when she's standing facing downwards, but I intend to get this issue sorted before I move on to the other directions.
Title: Re: Player unable to walk when using "looking around" function...
Post by: Mazoliin on Thu 21/07/2011 16:54:17
You could set a variable to indicate when Nancy is gazing and check the variable in on_mouse_click. Then simply call UnlockView if she is and reset the variable.
Title: Re: Player unable to walk when using "looking around" function...
Post by: Technocrat on Thu 21/07/2011 17:11:41
Ah, that's a good idea. I've rejigged the gazing function a bit...


function Nancy_Gaze() {
 
 if(player.Animating == false && IsNancyGazing==true){
  // Determine what direction Nancy is facing
 
 
  int FacingDir = player.Loop;
  int Neomousex = mouse.x + GetViewportX();

  if (FacingDir==0){
    if((Neomousex - player.x < 30) && (Neomousex - player.x > -30)){player.UnlockView();return;}
    if(Neomousex - player.x > 30){player.LockViewFrame(6, 0, 2);return;}
    if(Neomousex - player.x < -30){player.LockViewFrame(6, 0, 1);return;}
   
  }    
       
 }
IsNancyGazing=true;
 
}



...and added a bit to the on_mouse_click section


function on_mouse_click(MouseButton button) {

 
 // called when a mouse button is clicked. button is either LEFT or RIGHT
 if (IsGamePaused() == 1) {
   // Game is paused, so do nothing (ie. don't allow mouse click)
 }
 else if (button == eMouseLeft) {
   
     if(IsNancyGazing==true){
   player.UnlockView();
   IsNancyGazing=false;
 }
   
   ProcessClick(mouse.x, mouse.y, mouse.Mode );
 }


She'll now quite happily walk in any direction, except down. Hm, perhaps I'm telling it to do this wrongly...
Title: Re: Player unable to walk when using "looking around" function...
Post by: Mazoliin on Thu 21/07/2011 18:56:40
I did a quick test and it appears that walking or talking does not set player.Animating to true. So you just need to add some extra checks at the beginning, like player.Walking and player.Speaking

[edit] typo
Title: Re: Player unable to walk when using "looking around" function...
Post by: Technocrat on Thu 21/07/2011 22:11:34
Ah, that seems to be making it work. Thanks a lot!
Title: Re: Player unable to walk when using "looking around" function...
Post by: monkey0506 on Fri 22/07/2011 11:33:34
Just to be clear, Character.Animating is specifically used in conjunction with the Character.Animate function. As Mazolin stated, there are other properties, such as Character.Moving (not Walking ;)) and Character.Speaking which can be used to check for any potential automatic animations such as a walking or speaking animation being played.

Just a thought, the new Character.Move function might actually make the Moving property slightly more ambiguous in the regard of checking for animations though, seeing as Move will not play the walking animation whereas Walk does, yet neither sets the Animating property. So, if for any reason you ever had cause to be using both Character.Walk and Character.Move in the same game, and needed to differentiate between the two to check for a walking animation, you would need some type of custom script. Presumably, if you did, just checking that the Character.View matched the walking view and that the Character.Frame was non-zero should be sufficient. ;)

Oh, and IIRC the Speaking property is only ever set to true if the SpeechView is set and is actually being used to animate the character. So, characters with no SpeechView, or characters speaking in the background will never have the Speaking property set to true. If you for some reason needed to check for those cases, that too could be worked around via the script, but would be a bit more work (so let us know if you need help scripting something like that).
Title: Re: Player unable to walk when using "looking around" function...
Post by: Mazoliin on Fri 22/07/2011 16:08:30
Right, it's Moving, not walking. I've been messing around with plugins a bit too much latley :P