About 'Flip Character Sprite'!

In this video (objectives)…

  1. Introduce Mathf.Abs and Mathf.Sign.
  2. Pseudocode for flipping character sprite.
  3. Flip character sprite based upon player having horizontal velocity.

After watching (learning outcomes)…

Flip the player character's sprite whenever the character has horizontal velocity.

(Unique Video Reference: 11_TV_CU2)

We would love to know…

  • What you found good about this lecture?
  • What we could do better?

Remember that you can reply to this topic, or create a new topic. The easiest way to create a new topic is to follow the link in Resources. That way the topic will…

  • Be in the correct forum (for the course).
  • Be in the right sub-forum (for the section)
  • Have the correct lecture tag.

Enjoy your stay in our thriving community!

Hi Ben & Rick,

I really enjoy the courses and appreciate the level of effort and quality - keep up the good work.

Here’s what my Run() method looks like which was a slightly different route. I think I ended up in the same place, but I chose to manipulate the SpriteRenderer rather than the Transform.

private void Run()
{

    // Get control input
    float inputValue = CrossPlatformInputManager.GetAxis("Horizontal"); 

    // Calculate player speed
    float playerSpeed = inputValue * runSpeed;

    // Orient the player-facing direction, or leave last value / default value if zero
    if(playerSpeed < 0)
    {
        // Face left
        playerSpriteRenderer.flipX = true;

    } else if (playerSpeed > 0)
    {
        // Face right (Default)
        playerSpriteRenderer.flipX = false;
    }

    // Move player
    playerRigidBody.velocity = new Vector2(playerSpeed, playerRigidBody.velocity.y);

}

is there any advantage using the localScale over SpriteRenderer in this particular case? (I can also appreciate going a different route that allows for introductions to new Mathf functions.)

Not at all, in fact your method is arguably neater, we just missed that API. @Rick_Davidson note for Tile Vania.

Thanks for sharing this, its a neat alternative to our approach.

Privacy & Terms