Character "glues" to FaceLocation while on hotspot

Started by iamlowlikeyou, Thu 13/01/2011 14:52:16

Previous topic - Next topic

iamlowlikeyou

I'm trying to do this:

Code: ags

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

Calin Leafshade

FaceLocation is a *command*. It doesnt return true/false.

to check for direction you need to check a the loop

Code: ags

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


iamlowlikeyou

#2
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?

Calin Leafshade

maybe something like this

Code: ags


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

Code: ags


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




iamlowlikeyou

Okay, thanks!

I don't really understand this code, and can't get it to work at the moment, but I'll get studying :)

Khris

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.

SMF spam blocked by CleanTalk