Clearing up a bit I'm confused about

I was a bit confused at the line:

transform.localScale = new Vector2(Mathf.Sign(myRigidBody.velocity.x), 1f);

I just didn’t quite understand what

transform.localScale

did. It seems like we are changing the entire local matrix/coordinates/prefab to a negative scale factor…and this just seems really crazy to me that you would do that just to flip the player.

Obviously I must be missing something here, I just don’t know what. Any help?

To be a bit clearer: It seems like we are flipping the entire worlds coordinate system to negatively scale just to walk the other way.

What is actually going on? Thanks heaps :smiley:

Hi Monstertank,

Yes, there is a reason: We also want to flip the colliders. If the colliders are symmetrical, overriding the scale would not be necessary. However, if the player (or whatever) had a sword collider, we would also want to have that collider appear on the other side.

Maybe you know an alternative or even better solution for this problem? If so, feel free to share it with us. :slight_smile:


See also:

2 Likes

Thanks for the quick reply. That clears it up for me :slight_smile:

The real issue I was having I guess was that I lost track of what object ‘transform’ was transforming…I know its transforming the player, but I can’t see how as we aren’t running the code in a player prefab or anything.

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

Privacy & Terms