Increasing scale on Goobers issues

Having some issues with flipping enemy when I make the scale bigger. I saw previous discussion on it but do not fully understand the solution. How to use the new scale set of enemy to flip sprite and maintain scale?

Hi,

Welcome to our community! :slight_smile:

Could you please share more information on what you did and have in Unity? Screenshots might also be helpful.

1 Like

When you set the scale on an axis to negative, it flips the sprite on that axis, eg. setting the scale to (-1, 1) will flip the sprite horizontally. Now, if you scale the sprite to be twice the size, you need to maintain this negative value meaning you need to set it to (-2, 2)

1 Like

Hi sorry for the late reply, I changed the FlipSprite() from changing value of the transform scale to simply flipX on the Sprite Renderer

void FlipSprite() 
    {   
        if (enemyBody.velocity.x > 0)
        {
            enemySprite.flipX = true;
        } 
        else 
        {
            enemySprite.flipX = false;
        }  
    }

I was wondering if this approach has any flaws compared to the transform.localScale one? It seems to maintain the scale of the sprite as well.

Thanks

The only potential “flaw” I see is that your solution flips the sprite only but not the colliders. If the periscope collider is on the right-handed side of the goober’s centre and the goober sprite flips, the periscope would still remain on the right-handed side. You will have to test this edge case to figure out if it causes a problem in your game. If it does not, your solution is sufficient. As always, a solution depends on the context. :slight_smile:

Regarding your implementation, I’m showing you a little trick: enemyBody.velocity.x > 0f is a boolean expression whose value is either true or false. For this reason, you could use it “as it is”.

void FlipSprite() 
{   
    enemySprite.flipX = enemyBody.velocity.x > 0;
}

Done. :slight_smile:

However, if you prefer if/else, your current code is perfectly fine, too.


See also:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms