playMaker

Author Topic: Angle to Target (enemy always facing the player)  (Read 5365 times)

Kubold

  • Full Member
  • ***
  • Posts: 112
Angle to Target (enemy always facing the player)
« on: July 09, 2012, 10:20:17 AM »
Hey!

In sidescrolling platform game, I want to make the enemy play 'turning in place 180deg' animation, whenever the player is behind it. I figured I'll use Get Angle to Target.

The problem is that something doesn't work or I got something wrong. The float Angle2Player is always 0, and doesn't change at all during gameplay, regardless of where the Player is (in front or behind the enemy that has this script). Did I do something wrong or is it a bug?

See attached image.

jayhfd

  • Junior Playmaker
  • **
  • Posts: 71
Re: Angle to Target (enemy always facing the player)
« Reply #1 on: May 30, 2013, 10:47:36 PM »
If anyone was wondering... I saw this question asked a couple times as I had the same issue. I was putting the get angle to target action and float compare in the same state. If I ran one frame, it would grab the angle correctly. Not sure why this happens, but if you advance a frame/wait, you'll get it.

escpodgames

  • Hero Member
  • *****
  • Posts: 687
    • Assets
Re: Angle to Target (enemy always facing the player)
« Reply #2 on: May 30, 2013, 11:06:30 PM »
Make it everyframe?

jayhfd

  • Junior Playmaker
  • **
  • Posts: 71
Re: Angle to Target (enemy always facing the player)
« Reply #3 on: May 30, 2013, 11:32:34 PM »
Yeah I had done, but of course if you're trying to do something like "fire if looking straight at target", then you'll do a float compare on the angle, find that its zero, and move to your next state.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Angle to Target (enemy always facing the player)
« Reply #4 on: May 30, 2013, 11:48:01 PM »
For a 2d platformer all you have to do is check the angle, the only two directions are either greater or lesser than 180 degrees so just define the angle to the player each frame and if it is greater/less than 180 sent the look left/right event.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

jayhfd

  • Junior Playmaker
  • **
  • Posts: 71
Re: Angle to Target (enemy always facing the player)
« Reply #5 on: May 31, 2013, 09:42:14 AM »
I'm currently trying to do "if the target is right ahead of me (angle is <5 degrees), then fire an action" So I'm just using a float compare. When you need to wait a frame for it to get the angle, the result is always going to be 0 first, which makes this state/action think that the target is right in front of us.

Kind of seems like a bug to me?

Jay

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Angle to Target (enemy always facing the player)
« Reply #6 on: May 31, 2013, 10:20:54 AM »
Are you working on the XY? The action gets the angle based on forward direction (Z) so that may explain the 0 constantly.

If its periodically working, then its something to do with the FSM flow. What does the game look like? From the FSM it seems odd that you wouldn't check the angle every frame and control the enemy's direction in a separate FSM from your walking and such.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

jayhfd

  • Junior Playmaker
  • **
  • Posts: 71
Re: Angle to Target (enemy always facing the player)
« Reply #7 on: June 02, 2013, 09:25:06 PM »
XZ (top down), and yes it will get the angle var by using every frame, however that 1 frame of 0 kills everything. Can't even have another FSM checking the angle, as it will grab the zero. Have to end up fudging it by making that FSM wait .01 seconds before getting the angle.