Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Kubold on July 09, 2012, 10:20:17 AM

Title: Angle to Target (enemy always facing the player)
Post by: Kubold 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.
Title: Re: Angle to Target (enemy always facing the player)
Post by: jayhfd 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.
Title: Re: Angle to Target (enemy always facing the player)
Post by: escpodgames on May 30, 2013, 11:06:30 PM
Make it everyframe?
Title: Re: Angle to Target (enemy always facing the player)
Post by: jayhfd 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.
Title: Re: Angle to Target (enemy always facing the player)
Post by: Lane 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.
Title: Re: Angle to Target (enemy always facing the player)
Post by: jayhfd 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
Title: Re: Angle to Target (enemy always facing the player)
Post by: Lane 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.
Title: Re: Angle to Target (enemy always facing the player)
Post by: jayhfd 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.