playMaker

Author Topic: How to check player current facing position?  (Read 1057 times)

tulioricci

  • Playmaker Newbie
  • *
  • Posts: 2
How to check player current facing position?
« on: November 23, 2021, 12:06:28 PM »
I have this FSM inserted into a drawer prop in my topdown 2D game map, and I needed that the player could only start interacting with the drawer if he is facing the upward direction. I already manage to make a loop of opening and closing it based on whether he's inside the 2Dcollider.

Get Animator Current State Info would need to get the player animation state "Player_Idle_Up" but it only seems to work with GameObjects.

Also, there's seems to be a bug in FSM that if I keep opening and closing the drawer without leaving it's collider, for about 2 loops the FSM stops working and I need to leave the collider and enter back again. Any ideas why this happens aswell?

Best of regards.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: How to check player current facing position?
« Reply #1 on: November 23, 2021, 12:17:24 PM »
Hi.
you probably want a trigger that is a bit larger than the drawer and use trigger events.

but for both Trigger and Collider Events:
On Exit will only trigger when you exit the trigger while you are on that state.
if you exit the trigger/collider and you are on a different state and the state activate after that, it will not trigger the action any more since you already exited the collider.

For facing you can maybe set a int value (Player Direction) on the fsms where you do the movement.

Then use Get Fsm int to check the value. (for example 1=up, 2=right, etc.)

tulioricci

  • Playmaker Newbie
  • *
  • Posts: 2
Re: How to check player current facing position?
« Reply #2 on: November 23, 2021, 12:43:37 PM »
The problem is that even if I keep inside the collider and keep pressing space, after two times I press it and loop the FSM, it stops working. In order to make it work again, I have to leave the collider and enter back in it. This is not supposed to happen.

Also I'm using the movement of the Player via script, and not FSM. I cannot get fsms int values unless I remove the script and redo all the player movement via FSM (which I may, in the future - but I would love to see a workaround with animator checks).

EDIT: I solved the first issue. What I thought is that the TriggerStay2D was  supposedly not constantly checking if the Player was inside the trigger area, but it was. The main problem was that my player Rigidbody was set to "Start Awake", but once I changed to "Never Sleep" then the FSM worked perfectly.
« Last Edit: November 23, 2021, 04:54:15 PM by tulioricci »