playMaker

Author Topic: Substract Problem?[SOLVED]  (Read 426 times)

zerodragonheart

  • Playmaker Newbie
  • *
  • Posts: 4
    • View Profile
Substract Problem?[SOLVED]
« on: October 09, 2019, 05:47:56 PM »
Hi guys! I hope you can help me with this.
So,basicaly I have to flip the enemy sprite if the player is at his left.
Found that apparently the best way is to :
-Get player X position
-Get Enemy X position
-Compare both variables and if  the result is Greater scale to "1" if is less, scale to
 "-1"
Thing is is not working and also I'm getting this error message (at the bottom of the image)

" Froakin : Scaling : Loop count exceeded maximum: 1000 Default is 1000. Override in Fsm Inspector."


any thoughs on this?



« Last Edit: October 11, 2019, 01:59:04 AM by jeanfabre »

Athin

  • Full Member
  • ***
  • Posts: 152
    • View Profile
Re: Substract Problem?
« Reply #1 on: October 09, 2019, 06:34:03 PM »
Heya,

Got an infinite loop going on in that FSM somewhere. Check those two other states, are they constantly firing off maybe? 

Thore

  • Sr. Member
  • ****
  • Posts: 480
    • View Profile
Re: Substract Problem?
« Reply #2 on: October 09, 2019, 06:49:11 PM »
The loop is causing the problem, but the calculation is also not correct. You need to get current X position and float compare with player’s x position. Smaller = flip.

To do this robustly and efficiently, use the start state to initialise, where you get the own X scale once, store it in variable, then float operate it with *-1 and store the flipped x value as well. That’s a failsafe in case you use an enemy who is not scale.x = 1. If that never, absolutely, swear-to-god never happens, you can just set -1 as you do already.

Then, you basically never need the start state again. In the main part, you need just two states that transition to each other. The first checks if the player’s pos is smaller than the own, and underneath set the X scale (not flipped). The greater or equal events are left blank. But when the player’s pos is smaller, go to the other state with identical actions. Only here, the smaller than and equal is left blank, and underneath the action you set the x flipped value you stored away. Depending on your game, all these states would run every frame.
« Last Edit: October 09, 2019, 06:51:27 PM by Thore »