Turn Around, Bright Eyes

Started by Baron, Wed 22/09/2010 04:27:58

Previous topic - Next topic

Baron

When using "characters turn before walking", is there an easy way to ensure that the character always turns towards the screen (frontal view) rather than away, unless the character is actually turning to go backwards?  For example, my character faces left, the walk icon is clicked, and then she moves right by turning away, instead of towards me.


ThreeOhFour

I know it can be done, as Leafshade does this.

But I mainly posted in here to say that you put that song in my head  ;D

Dualnames

Quote from: Ben304 on Wed 22/09/2010 06:36:02
But I mainly posted in here to say that you put that song in my head  ;D

Yes my point there too. :P
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Baron

Every now and then I get a little bit tired of listening to the sound of my tears.

But seriously folks, to the problem at hand.  I think I've found Leafshade's solution posted on the forums -I can't find the thread right now, but wasn't it something to do with a phantom player sprite which the visible player would follow?  This strikes me as a quick fix that might end up causing unforeseeable complications down the road in the development process.  So is the consensus that the clockwise turning is hardwired and there's no easy way out of this?  Maybe we'll just try it without the turning and see how it looks.

Calin Leafshade

Calin Leafshade to the rescue!

Actually this is not that hard to do but quite complicated

first you need to disable the "turn before walking feature"
then check where the mouse click is and find out which way to face the character, this is the hard part.
There are 2 ways of doing this:
The easy why is to check where the mouse click is, relative to the PC and guess which way the PC should face, heres a little function that will do this:

Code: ags

//AbsInt is just a function that gets the absolute value of an int.
//i.e
function AbsInt(int val){
if (val < 0) return val * (-1);
else return val;
}


if(!player.Moving){
          int RelativeX = mouse.x + GetViewportX() - player.x;
          int RelativeY = mouse.y + GetViewportY() - player.y;
          if (RelativeX > 0 && AbsInt(RelativeX) > AbsInt(RelativeY)) player.FaceDir(eCharRight);
          else if (RelativeX < 0 && AbsInt(RelativeX) > AbsInt(RelativeY)) player.FaceDir(eCharLeft);
          else if (RelativeY < 0 && AbsInt(RelativeX) < AbsInt(RelativeY)) player.FaceDir(eCharUp);
          else if (RelativeY > 0 && AbsInt(RelativeX) < AbsInt(RelativeY)) player.FaceDir(eCharDown);
       }



This method is fairly good except it may have problems with more complex walkable areas since you cant predict the pathfinder.
The alternative is to use and invisible character.
Send the invisible character walking to the mouse click, wait for one loop and then you can see which direction your PC should face.

As for the actual facing function you just need to check which way the play is currently facing and then face them the new direction via the front by messing with the loops manually.

Baron

#5
Thanks for the ideas Leafshade.  I tried the phantom character and didn't like the effect, so I've adapted your idea slightly:

Code: ags

function charturn (){ //turns the player frontwards on Walkto mouse click (or manually for Blocking event)
 int absy;
 if (mouse.y < cplayer.y) absy = (mouse.y - cplayer.y) *(-1);
 else absy = mouse.y - cplayer.y;
 if ((cplayer.Loop ==1)&&(mouse.x>cplayer.x) && (mouse.x -cplayer.x > absy)) {
           cplayer.Loop =0; 
           mouse.DisableMode (eModeWait); 
           Wait (5); 
           mouse.EnableMode (eModeWait);
  }
}


   This is called right before processing left-click if Walkto mode is enabled, and works well with "turn player character" turned on -I'm happy with the feature except for the left-to-right turn.  So, this function turns the character forwards if she is facing left but is likely to go right (and the turn player character does the rest).  It works perfectly, except my cursor flickers to wait when the turn is in process.  No matter, I thought to myself, I'll just disable it temporarily while the function runs its course, but no!  The cursor still flickers to the hourglass despite that cursor being disabled!  I'm so close -any ideas?

EDIT LATER THAT DAY: Nevermind, I've solved it by switching the Wait cursor graphic to the currently used one (probably walkto, but who knows) and then back.  Thanks for everyone's help!

SMF spam blocked by CleanTalk