Why check flipping on every update?

Unique Video Reference: 14_IW_UPC

Since the slimes are only ever changing their movement direction when they decide on a new target direction in MoveTo(), wouldn’t it be much better to just set their flipping inside there instead on every FixedUpdate() ?

(Knockback or being hindered by an obstacle doesn’t change their ways in which they continue sliming, so no influence from there as well…)

6 Likes

Not a bad idea

    private void FlipSprite()
    {
        if (_moveDirection.x < 0)
        {
            _spriteRenderer.flipX = true;
        }
        else
        {
            _spriteRenderer.flipX = false;
        }
    }

    public void MoveTo(Vector2 targetPosition)
    {
        _moveDirection = targetPosition;
        FlipSprite();
    }
6 Likes

@Stephen_Hubbard Nice little optimization here

3 Likes

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

Privacy & Terms