Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: iamlowlikeyou on Thu 13/01/2011 14:52:16

Title: Character "glues" to FaceLocation while on hotspot
Post by: iamlowlikeyou on Thu 13/01/2011 14:52:16
I'm trying to do this:


function hotspot1_Standing(){
   if (if player.FaceLocation(x, y)){
      labelFunction.Text = "blah blah";
   }
   else{}
}


The purpose is that when player walks onto the hotspot, AND is facing the given location, a label will display the name of the thing on that location. Could as well be an object or anything else of course...
My problem is, that when player walks onto hotspot while facing the location, the player is kind of "glued" to the FaceLocation, which means that if player walks away again, he will keep turning to face the location until he is out of the hotspot.
I can't really grasp what's wrong with the code - besides the code is so very simple and fundamental, that I'd think it pretty hard to overlook something :D
Title: Re: Character "glues" to FaceLocation while on hotspot
Post by: Calin Leafshade on Thu 13/01/2011 15:18:40
FaceLocation is a *command*. It doesnt return true/false.

to check for direction you need to check a the loop


if (player.Loop == 0 ) {
   
         //Facing down
}
if (player.Loop == 1 ) {
   
         //Facing left
}
if (player.Loop == 2 ) {
   
         //Facing right
}
if (player.Loop == 3 ) {
   
         //Facing Up
}

Title: Re: Character "glues" to FaceLocation while on hotspot
Post by: iamlowlikeyou on Thu 13/01/2011 15:39:50
I see.
But I still don't understand why it glues...?

But how do I run a repeating check if the player is facing a specific location?
It seems that simply checking for direction won't be fully sufficient for this purpose, as the player has to face opposite directions regarding where in the hotspot he's standing, which means that while it's true that he's facing the "object" while facing left when he's on right side of "object", but it's the opposite when on the left side, if you can follow me?

EDIT: Sorry, now I understand why it glues. I got it totally mixed up, because at first I didn't understand the term "command". But yeah, I need to somehow CHECK if player is facing a specific location. Is this possible?
Title: Re: Character "glues" to FaceLocation while on hotspot
Post by: Calin Leafshade on Thu 13/01/2011 15:55:04
maybe something like this



function AbsInt(int Val){
 if (Val < 0) return (-1 * Val);
 else return Val;

}

function IsFacingLocation(this Character*,  int x,  int y) {
         
         int checkLoop;
         int RelativeX = x + GetViewportX() - this.x;
         int RelativeY = y + GetViewportY() - this.y;
         if (RelativeX > 0 && AbsInt(RelativeX) > AbsInt(RelativeY)) checkLoop = 2
         else if (RelativeX < 0 && AbsInt(RelativeX) > AbsInt(RelativeY)) checkLoop = 1
         else if (RelativeY < 0 && AbsInt(RelativeX) < AbsInt(RelativeY)) checkLoop = 3
         else if (RelativeY > 0 && AbsInt(RelativeX) < AbsInt(RelativeY)) checkLoop = 0;
         
         return (this.Loop == checkLoop);


}



all untested

usage is like this



if (cEgo.IsFacingLocation(10,10)) cEgo.Say("Yes i am facing is this direction");



Title: Re: Character "glues" to FaceLocation while on hotspot
Post by: iamlowlikeyou on Thu 13/01/2011 16:27:31
Okay, thanks!

I don't really understand this code, and can't get it to work at the moment, but I'll get studying :)
Title: Re: Character "glues" to FaceLocation while on hotspot
Post by: Khris on Thu 13/01/2011 17:56:32
All you want to do is check player.Loop, really.

Also you should use Regions, not Hotspots, the event "standing on hotspot" is included for legacy purposes, it's from when there weren't Regions implemented yet.