Тёмный

HOW TO FLIP YOUR SPRITE IN UNITY 🎮 | Flip Your Player In Unity | Unity Tutorial 

Dani Krossing
Подписаться 474 тыс.
Просмотров 58 тыс.
50% 1

Hi everyone! 🙂 Today I will show how to flip your 2D character in Unity.
Learn C# here: • 1: Introduction To C# ...
Download Unity here: unity3d.com/get-unity/download
➤ TIMESTAMPS
00:00:00 - Intro
00:01:01 - My player script so far
00:01:48 - Method 1: Flip player (the fast way)
00:03:42 - Method 2: Flip player (the good way)
➤ GET ACCESS TO MY LESSON MATERIAL HERE!
First of all, thank you for all the support you have given me!
I am really glad to have such an awesome community on my channel. It motivates me to continue creating and uploading content! So thank you!
I am now using Patreon and RU-vid Memberships to share improved and updated lesson material, and for a small fee you can access all the material either from my memberships or Patreon, depending on your preference. I have worked hard, and done my best to help you understand what I teach.
I hope you will find it helpful :)
Memberships: / @dani_krossing
Patreon: / mmtuts

Опубликовано:

 

25 июн 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 81   
@mintydog06
@mintydog06 Год назад
Thanks. The advice at the start was also help, about how to improve play performance simply by clicking on the scene so that there isnt a lot of things in the inspector. I never knew that.
@shuffle8
@shuffle8 Год назад
Thank you this is super straightforward!
@ChapCanai
@ChapCanai Год назад
Thanks, your method also worked for other scales instead of having to be fixed at 1
@LSPTaris
@LSPTaris Год назад
Thank you so much ! Could not get the child objects to flip with the character until using this !
@autolearn738
@autolearn738 Год назад
Im so glad to see this solution I tried to resolve for 3 days, you have one fallower more. Thanks a lot. You are the best teacher. 👏❤
@SilverCat75
@SilverCat75 6 месяцев назад
you're a fricken lifesaver!!! thanks so much for these tutorials! I've actually learned so much just through you stuff!
@der_timon7024
@der_timon7024 2 года назад
Thanks, helped me a lot
@ITYWTD_
@ITYWTD_ Месяц назад
Learning to create custom animations for my games, thanks!
@Manuella15
@Manuella15 10 месяцев назад
Thanks a lot for the tutorial!
@bossfakealeks12345
@bossfakealeks12345 Год назад
Thank you, very well and good explained
@mabiii4817
@mabiii4817 Год назад
Thanks you very much! nice tutorial!
@BlazingFunk
@BlazingFunk Год назад
Thanks that was what I looked for.
@nickminick7454
@nickminick7454 2 года назад
Interesting Video!
@marcosantos9512
@marcosantos9512 Год назад
Thank you so much man!
@dheebhanjeganathan1041
@dheebhanjeganathan1041 Год назад
Yo homie u saved my life on the mechanics animation. mini project with swordman prefab. I had to use enum because boolean would be too confusion.
@Surzom
@Surzom 2 года назад
thank you so much, subbed
@sebastianmller4544
@sebastianmller4544 6 месяцев назад
Thanks!
@user-jj2om3xg7p
@user-jj2om3xg7p 3 месяца назад
Bro i don`t know how to thank you ! you saved my life in the minute 3:58 when you said that Vector come by default float so you must put (f) after each number or he will think it`s double, i have sarch for days for this problem (Cannot Convert Argument from Double to a float) and i just fixed it, Thank you 3>
@f3rnando065
@f3rnando065 2 месяца назад
thanks a lot
@buildworldswithme
@buildworldswithme Год назад
Seen this video. Thought to myself "You HAVE to subscribe to this dude" Only to come here and find out I already subscribed long ago.
@RanilSuper
@RanilSuper Год назад
Thanks you!
@ObitoUchiha-zu9yn
@ObitoUchiha-zu9yn 2 месяца назад
Thanks
@GamingGables
@GamingGables Год назад
Hi Dani! I am having an issue when adding animation. When I move left, the "walk_face_right" animation still plays. When I stop, my character sprite flips to face left. Before adding this code my "walk_face_left" animation worked. Do you have any suggestions? Thank you for this awesome tutorial!
@roberttrottini9660
@roberttrottini9660 Год назад
I’m having an issue where my pivot point isn’t centered and when the character flips, it moves along a pivot that I don’t want. Is there a way to move the pivot point to be equal to the center point?
@vikaskumar-lr4cn
@vikaskumar-lr4cn 2 года назад
Hello, I have made a car wheel in blender and baked normal map highpoly to lowpoly it's looks good in blender but when I import in unity normal map doesn't looks good as looks in blender what could be issue. And what is the better way to make normal map in blender for unity or other game engines
@javazombi
@javazombi 9 месяцев назад
Thanks! This got me untuck in minutes.
@Stoney_Eagle
@Stoney_Eagle 2 года назад
What if you create a feature on your website where you have keywords that finds videos and gives you a timestamp where that subject is explained? This would work for every tutorial you've made 😉 And if you do some awesome SEO you'll gain a ton of external views too.
@cozmo_Comet
@cozmo_Comet 4 месяца назад
Its crazy how one small error can cause something to not work lol, anyway this helped me find my issue. Thanks!
@HUSEYINBERIK
@HUSEYINBERIK 6 месяцев назад
Hi Dani my character slides quick of he side either direction and carries on moving ? what could be the issue?
@akithemacaw8212
@akithemacaw8212 Год назад
Perfect tutorial, unless your character isn't scaled to 1, 1, 1. My scaling is too small for it to work, even if I put in the right numbers
@pkuuuu
@pkuuuu Год назад
Hey, stupid question. Why do we need to delcare gameobject.trasnform.localSclae = currentScale again?
@reystation4570
@reystation4570 2 месяца назад
For Godot users: This can also be applied in Godot.
@snowballzyt
@snowballzyt Год назад
How can we make it follow the mouse? Like flip when mouse is on the left or right.
@der_timon7024
@der_timon7024 2 года назад
Could you pls do a Tutorial for rotating the player in the direction he moves. (top down 2D)
@Dani_Krossing
@Dani_Krossing 2 года назад
I uploaded one a few days ago ^^
@Pixeleyesd
@Pixeleyesd 3 месяца назад
how do you add jump?
@reploidzero9058
@reploidzero9058 9 месяцев назад
can someone help me? i copied your movement script and my guy slides around like hes on ice? how do i prevent this?
@HienLe-lf2xc
@HienLe-lf2xc Год назад
I like your hair 😆😆
@Luke_Du_Plessis
@Luke_Du_Plessis 2 месяца назад
Thank you, saved so much time🙏
@TheTrickyify
@TheTrickyify Год назад
Edit: This is easier for me in the way that I understand it better, it is just that you won´t be able to call this function if you would like to flip the character in another scenario like for a cutscene or such :) I made a bit easier method of the good solution for this, just as he did, create a float inputHorizontal and bool facingRight = true in the beginning of the public class PlayerController. Then make the function FixedUpdate() and in there get the horizontal as shown but in the if statements keep it as the "bad example" just add in the if statement of facing right with inputHorizontal > 0 && facingRight == false and the left inputHorizontal < 0 && facingRight == true and inside add the gameobject rnasform as shown but also in the right one you set facingRight = true; and in the left one you set facingRight = false; Less code and it only runs when flipping the other way. Hope this made sense
@Dani_Krossing
@Dani_Krossing Год назад
From what you describe, if I’m understanding it correctly, the only difference is that you are doing the same exact same thing as my “good example”, but without using a separate method. 🙂 Also, the part in Flip() with the “facingRight = !facingRight”, does the exact same thing as setting “facingRight = false” and “facingRight = true”. So what you are describing is the same as my last example, but combining the Flip() method directly into FixedUpdate(). 🙂 Your way is definitely a valid way to do it. 😊 However it is less reusable if you at some point need to flip the character, for some other reason. Since you would have to re-write the code again.
@TheTrickyify
@TheTrickyify Год назад
@@Dani_Krossing Ah I see, that makes sense. I am using a 2d controller that was already made that I liked for my game so I am adding to that script, so your good way didn´t really work for me and I didn´t understand how it worked so I came up with it like this so it made sense to me but if I would need to face my character in another direction for any reason I have this video to go back too! Thanks alot :D
@mohamedalmatter9073
@mohamedalmatter9073 Год назад
he making flip when i jump and go left or right but when i go right or left its not flip
@Ronin----
@Ronin---- 7 месяцев назад
Thanks for the video great help. Also on an unrelated note are you related to Elon Musk? the similarities are uncanny
@baseddino
@baseddino 2 года назад
thanks this wasn't in the 2d character movement video
@ItsAkile
@ItsAkile Год назад
Tried a few methods but the Left movement constantly jitters my animation < > < >, the right side gets stuck right but sometime flip facing left while moving right . is it something to do with the animations
@Dani_Krossing
@Dani_Krossing Год назад
That issue happens when your player flips twice in one direction, and not in the other. It is most likely because your "flip check" when you move, is set incorrectly. :) Happens to me some times too hehe.
@sabfinlay-smith5773
@sabfinlay-smith5773 Год назад
@@Dani_Krossing I'm having this issue too! first time coder :') what's a flip check and how can I go about correcting it? I followed your code to a T but can't see any errors!
@michi8050
@michi8050 11 месяцев назад
but how about up and down?
@darkernessto9229
@darkernessto9229 11 месяцев назад
I cant flip my character XoX .help ,please....
@neozoid7009
@neozoid7009 2 года назад
This method also changes the sprite scale to 1,1,1 . But I want to have the scale to the same as I scaled it in the editor .
@Dani_Krossing
@Dani_Krossing 2 года назад
If you don't want the scaling to change, then you create a separate sprite which is mirrored, that you then activate whenever going to opposite direction.
@neozoid7009
@neozoid7009 2 года назад
@@Dani_Krossing awesome but how can I change the normal map , If I flipped the the sprite the normal map doesn't flip !
@guidesforuseveyone6834
@guidesforuseveyone6834 Год назад
@@neozoid7009 dude this 100% does not set the local scale to anything other than its opposite. How can multiplying by negative 1 change any number? if it is actually, do not change (localscake.x) but instead change entire local scale by new vector 3 and put in the values you have alreadu and just put a negative sign on the x. only thing Flip() does is take the x part of the local scale and multiply it by negative 1 which effectively flips it. DO NOT, mirror sprite like he is talking about if you wish to go with performance and have a bunch of moving parts. Though it wouldent be tjat bad i guess just weird if you have a bunch of colliders etc.
@neozoid7009
@neozoid7009 Год назад
@@guidesforuseveyone6834 thanks
@somedude8728
@somedude8728 Год назад
I know im late here but the way I did this was if (Input.GetAxisRaw("Horizontal") > 0){ gameObject.transform.localScale = new Vector3(Mathf.Abs(gameObject.transform.localScale.x),gameObject.transform.localScale.y,gameObject.transform.localScale.z); } if (Input.GetAxisRaw("Horizontal") < 0){ gameObject.transform.localScale = new Vector3(-(Mathf.Abs(gameObject.transform.localScale.x)),gameObject.transform.localScale.y,gameObject.transform.localScale.z); } so it would just set the x to a positive number when going right and negative when going left without actually changing it, dunno if its a good way to do this though
@irinidanavasi1666
@irinidanavasi1666 2 года назад
How do i fix: 《Transform does not contain a definition for localscale and no accessible extension method localscale accepting a first argument of type transform could be found》?
@doubleyobro2647
@doubleyobro2647 2 года назад
3 months late but its localScale, with a capital S
@ghostisbusy2170
@ghostisbusy2170 Год назад
dosent work with animations
@kelly_daniel_official
@kelly_daniel_official 2 года назад
Don't you do PHP tutorials again
@kabhikachambala3392
@kabhikachambala3392 2 года назад
It is too far from me.
@lukegreenelsh4456
@lukegreenelsh4456 2 года назад
The Elon Musk of game design. Nailed it, thanks.
@archsteel7
@archsteel7 2 года назад
Don't insult them like that
@van641
@van641 Год назад
elon musk is a dumbass why would you even compare the two lmao 😭
@MoneyAlgorithim
@MoneyAlgorithim 2 года назад
Sir can you do tutorial for When player hit the objects Pausing game and give him 2 choises for continue 1 pay With Coins 2 continue with ADS And if he dosent press any button for 3 seconds Game back to main menu scene Its like subway surfer game over system i need this please tutorial can you do it
@EpicBunty
@EpicBunty 2 года назад
no thats so bad
@MoneyAlgorithim
@MoneyAlgorithim 2 года назад
@@EpicBunty no thanks i done it 😁
@EpicBunty
@EpicBunty 2 года назад
@@MoneyAlgorithim cool good luck getting nobody to play ur game lol
@jager356
@jager356 Год назад
why does unity dont have a fucking flip function so anoying
@Dani_Krossing
@Dani_Krossing Год назад
It does. Inside the Inspector.
@jager356
@jager356 Год назад
@@Dani_Krossing found it Spriterenderer. Flip but I need to change all my images to sprite renderer I hate it
@Dani_Krossing
@Dani_Krossing Год назад
@@jager356 You are just one big fluffy rainbow, aren't you 😂 How about that tedious "double clicking" every time you gotta open Unity Hub? Such a drag 🙄😂
@jager356
@jager356 Год назад
@@Dani_Krossing autostart
@jager356
@jager356 Год назад
Did it with scale how u did in ur video it works thx btw
@yeeyee_anime
@yeeyee_anime Год назад
i hate boolenas
@zadeh79
@zadeh79 Год назад
gameobject.transform.localScale = new Vector3(-1f, 1f, 1f);
@cardario5323
@cardario5323 Год назад
Bruh why did n't you just do transform.localScale = new Vector3(transform.localScale.x * -1, transform.localScale.y, transform.localScale.z);
@Dani_Krossing
@Dani_Krossing Год назад
There are many ways to do the same thing. If your code works for you then do that. 🙂
@cardario5323
@cardario5323 Год назад
@@Dani_Krossing ok man. DId n't expect you to answer your comments that frequently. You earned a sub bro
@quart7272
@quart7272 2 года назад
Thanks
Далее
TOP DOWN MOVEMENT in Unity!
22:30
Просмотров 1,2 млн
Escaping Unity Animator HELL
18:18
Просмотров 496 тыс.
Idle, Run and Jump Animations - Platformer Unity 2D
10:13
The Unity Tutorial For Complete Beginners
46:39
Просмотров 3,2 млн
2D Projectiles in Unity - Tutorial
25:19
Просмотров 2,2 тыс.
AIs learn to WALK
20:21
Просмотров 53 тыс.