How to tell if one actor is "facing" another actor?

maxerovmaxerov Member Posts: 9
edited November -1 in Working with GS (Mac)
I'm making a game where Actor 1 moves and turns randomly and when it faces Actor 2 an event is triggered. I have made a rudimentary system with complicated math but it has a lot of bugs and doesn't really work. Does anyone have any ideas as to how to do this?

Comments

  • jb15jb15 Member Posts: 602
    You're using "VecterToAngle"? (Less than, and greater than)

    For instance, if actor A's VecterToAngle to actor B (you'll need to constrain B's x and y as global attributes) is less than 180 and more than 0, then it's "facing" actor B.
  • PhoticsPhotics Member Posts: 4,172
    Constrain an invisible actor to the main hero actor.

    heroX
    heroY
    Rotation

    Use COS/SIN to make that actor move in a circle.

    If the other actors overlap with that actor, it's in the hero's line-of-sight.

    If COS/SIN is scary to you, The Unofficial GameSalad Textbook has a great math chapter.
  • maxerovmaxerov Member Posts: 9
    I used this function: atan(( game.PlayerY - self.Position.Y )/( game.PlayerX - self.Position.X )) where PlayerX and PlayerY are global attributes (like you mentioned) that represent the Actor 2. self is Actor 1. I compared the results of this function to Actor 2's self.Rotation. Is VectorToAngle some sort of attribute in Gamesalad or is it a function I have to add myself?
  • maxerovmaxerov Member Posts: 9
    to Photics:
    I was actually going to have it the other way around so that multiple instances of the Actor 2 would be looking for the Actor 1 (or hero actor). Would your system still work for that?
  • jb15jb15 Member Posts: 602
    VecterToAngle gives you an angle between two points--as in, it tells you that actor A is at a 75 degree angle to actor B. If you look in the dropdown box in GS, it's there.
  • PhoticsPhotics Member Posts: 4,172
    maxerov said:
    to Photics:
    I was actually going to have it the other way around so that multiple instances of the Actor 2 would be looking for the Actor 1 (or hero actor). Would your system still work for that?

    I'm not sure about what you're exactly trying to do. There was a discussion about line of sight in another thread.

    http://gamesalad.com/forums/topic.php?id=22982

    I added line of sight to BOT. It works great. There's an invisible actor that does much of the work. It's position/rotation is constrained to TANK's X,Y and rotation data. The rest is just using rules to detect for overlaps.
  • maxerovmaxerov Member Posts: 9
    jb15 said:
    VecterToAngle gives you an angle between two points--as in, it tells you that actor A is at a 75 degree angle to actor B. If you look in the dropdown box in GS, it's there.

    Oh I see. Trying that it seems like it only gives me the angle between the actor and point (0,0). Is there a way to make show the angle between the two actors? Am I missing something?
    Photics said:
    I'm not sure about what you're exactly trying to do. There was a discussion about line of sight in another thread.

    http://gamesalad.com/forums/topic.php?id=22982

    I added line of sight to BOT. It works great. There's an invisible actor that does much of the work. It's position/rotation is constrained to TANK's X,Y and rotation data. The rest is just using rules to detect for overlaps.

    Sorry for not being specific. I am trying to give enemies a "line of sight" so that something happens if they "see" the player. I thought about the method of just attaching an invisible sight actor to the enemies also. However, I don't know how I would get this method to work with multiple instances of the same enemy actor.
  • PhoticsPhotics Member Posts: 4,172
    maxerov said:
    Sorry for not being specific. I am trying to give enemies a "line of sight" so that something happens if they "see" the player. I thought about the method of just attaching an invisible sight actor to the enemies also. However, I don't know how I would get this method to work with multiple instances of the same enemy actor.

    OH... you want to do the reverse. Now I understand.

    That's tricky.

    If self.rotation = vectorToAngle(TANK.X - Self.position.X , TANK.Y - Self.position.Y)
    Then change self.aggressive to True

    You could add a little bit of a variance too with two rules...

    If self.rotation < vectorToAngle(TANK.X - Self.position.X , TANK.Y - Self.position.Y) +10

    If self.rotation > vectorToAngle(TANK.X - Self.position.X , TANK.Y - Self.position.Y) -10

    I'm not sure if this works, but it might be something to try.
  • jb15jb15 Member Posts: 602
    You can change the numbers 0,0--even use global attributes.
  • maxerovmaxerov Member Posts: 9
    jb15 said:
    You can change the numbers 0,0--even use global attributes.

    Sorry stupid question. Thanks.
    Photics said:
    OH... you want to do the reverse. Now I understand.

    That's tricky.

    If self.rotation = vectorToAngle(TANK.X - Self.position.X , TANK.Y - Self.position.Y)
    Then change self.aggressive to True

    You could add a little bit of a variance too with two rules...

    If self.rotation < vectorToAngle(TANK.X - Self.position.X , TANK.Y - Self.position.Y) +10

    If self.rotation > vectorToAngle(TANK.X - Self.position.X , TANK.Y - Self.position.Y) -10

    I'm not sure if this works, but it might be something to try.

    That's about as far as I got (but vectorToAngle would have made it way easier haha). It gets complicated though because the way that vectorToAngle measures a rotation from say 3 o'clock to 6 o'clock counterclockwise it goes from 0° to -90° whereas if you rotate the object on its own (self.Rotation) it goes from 0° to 270°. So I guess it's time to brush up on my coordinate geometry.
Sign In or Register to comment.