Hi there,
Quick question about flipping sprites in a 2D game based on the left/right direction.
In the recent Unity examples (if I understand them correctly), they use a "Flip" function combined with the horizontal axis input and a facingRight bool to flip the player sprite (or perhaps the entire world... I'm unsure) based on their current direction, and I'm just struggling a little to convert this into a Playmaker FSM. I realise I could just use their existing script and modify it as necessary, but, simply as a learning experience and to try to keep everything in Playmaker, I thought I'd ask for a little help on here. So, there are two parts to their script:
// If the input is moving the player right and the player is facing left...
if(h > 0 && !facingRight)
// ... flip the player.
Flip();
// Otherwise if the input is moving the player left and the player is facing right...
else if(h < 0 && facingRight)
// ... flip the player.
Flip();
AND
void Flip ()
{
// Switch the way the player is labelled as facing.
facingRight = !facingRight;
// Multiply the player's x local scale by -1.
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
I'm fine with the first section, using a Float Compare and a Bool Test (although feel free to tell me if there's a better way of doing it), but I can't quite figure out the Playmaker actions and state arrangements that would be best to use for the second part, specifically, just the "Multiply the player's x local scale by -1" part.
Any advice?
It sounds like this guy has nailed it already, but he doesn't appear to explain how:
http://hutonggames.com/playmakerforum/index.php?topic=6302.msg30613#msg30613P.S. I'd also like to take this opportunity to say how amazing Playmaker is! Good job, guys.