Two guestions about flipping sprites

Question one. Is there a reason we don’t use SpriteRenderer.Flipx = true / false when the player is moving? Could this cause problems elsewhere later on? It seems alot simpler

image
Now it’s set to moveInput but it could as well be velocity.x

Second.

At no point before have we talked about number in booleans. How is value playerHasHorixontalSpeed set to false or true when the calculation is just a number comparison.

How else could this be used?

You can do it that way… but it’s safer to do it this way. This way is independent of input/programming choices.

When you’re playing games, it’s typical for the direction of the player to be determined by the direction in the controller. If you get knocked back, say by an enemy hit, you don’t necessarily want your character to change direction.

That being said, if you did want the character to change like that, you can.

I don’t get what you’re asking.

Hi Michael!

The question about number in booleans refers to 6:00 of the lecture where Rick sets the boolean to be equal to a calculation result

I was wondering how does this work? How else could this be used it hasn’t been mentioned in previous lecture on this course. What determines of the boolean is true or not?

Is this basically an If-statement?

So is

bool exampleBoolean = 1 > 0

The same as coding

if (1 > 0)
{
exampleBoolean = true;
}

About using FlipX = true.

I also did some research on this and there infact is a downside to using this. It only flips the sprite that renderer is responsible for. If the player character is made up of several sprites it would flip just the one and also it would not flip any colliders attached to the sprites if they are direction-sensitive.

Flipping the transform of the entire parent gameobject does much more than flipping a sprite. In some instances flipping the sprite could be all you need but not always.

1 Like

Just so you know, I don’t know what video you’re referring to.

I don’t see it written that way too often, but yeah, it’s basically the same result, just a different syntax. You’ll see plenty of things like this in C# and other languages. Some, like this one is just a syntax of the language, others are syntaxtic (spelling?) sugar seen in a language like C#.

This is kind of true.

I like that you are thinking. As you’ll learn over time, there are almost always downsides to each methodology. When you’re learning, you’re adding tools to your toolbox and picking the appropriate tool for each circumstance. Think of it like this, you start learning programming and you’ve given a hammer. It works for every nail you want to hammer in, but there’s a downside. What if you want to slow down your car? Do you beat it with a hammer? No, you use a different tool and press the brakes.

Rick is just introducing you to a lot of tool you can use and sometimes he’s showing you different ways to accomplish each task. Some work better than others, but flipping the sprite is often done in 2d games to switch directions.

1 Like

Privacy & Terms