Easy character move with mobile joystick in unity | cinemachine| | hyper casual |

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone today we are making a joystick system for our Unity mobile games similar to this one as you can see we can move we can rotate and we are also playing our character animations so let's get it started you can see this is our starting scene on the scene we have some environment components and a ground is just a plane and trees these models I got from tennis asset stores those are free I will add the link uh for the environment and the character model as you can see this one okay I will add these links I mean downloadable links on video description Okay so this character as you can see has an animator controller and have two animations here so first we need to import a package okay this one joystick pack and it's free by the way so for if you are using it for the first time you have to download it and import now uh after importing let's create a script called um character movement manager okay so take a empty game object and name it this one and then reset add the script so we are using joystick pack but if you want to you can use like your own joystick controller but this one is for free and it's a snow box and it works perfectly okay so and we have to do we have to set up our input first okay so let's kill the skin size and after importing the joystick pack you will get this folder then go to prefabs and use the variable joystick okay so I'm using variable joystick uh the reason I'll show you okay first let's reset the value and so now if we run it see it's working our input UI input is working then if you are using this pack you can also use like floating yeah and my favorite one Dynamic one this is my favorite if you if you play a lot of hyper casual game all mobile games maybe you will see something similar to this you know so now uh our Target is to control player movement from this input okay so let's change it to Dynamic and character moving manager open it let's fix the name is first fast okay and delete the M default methods first uh we need to get the access of I have our joystick Direction Okay so public variable joystick and variable Joy um joystick then we are going to create a method public byte this first enable enable joystick input which are seek input for that we need to reference public canvas input canvas and also you are going to declare a Boolean valuable okay public pool is joystick is joysticks true and we're going to input canvas that's okay sure I'm using this method that's because sometimes uh on your games especially in hyper hyper casual games you can have multiple inputs like tab then joystick so you can declare a method for this one we only have one input so I'm calling I am enabling this joystick input from here okay now we are going to call update if our joystick input is true uh where uh movement Direction we're going to get the direction from our joystick inputs Okay so new Vector tree joystick.direction.x 0.0 F and then joystick dot deduction dot y if uh anyone not understanding like Y is 0 f that because joystick is a 2d okay is it 2D we are getting the value in 2D but we want to move our character here in 3D space right so we don't want to go up we just want to go z-axis then x axis okay so that's why we are keeping our y value to 0. no we got a move Direction let's move it right now for moving our objects we need another component you can use like uh first let's see later character and then add a character controller and for movement I'm using character controller but you can I mean it's up to you you can use a simple rigid body then move with it but uh on my experience I saw some jittering on whenever I try to use rigid body so forums but I I think you can fix it but for me I think it's convenient to use this character controller is easy it just and it has a default method I'll show you how Okay so just take public character controller controller okay now we're going to use character controller.simple move to movement Direction and we are going to multiply it with the movement speed movement speed yes ability okay we need to declare this variable public float we'll miss a bit okay you see this is just one line of code and it should be working okay first we need to assign our variables here we're going to use our joystick uh canvas first and or variable joystick here character controller let's say five and if we play right now our character should move you see our character is moving uh if anyone is seeing our character is move from T post that's because it has like at idle state it just is I just said okay so now our character is moving from our input and now what we want to do is rotate our character right so for rotating your character we need like also if movement Direction Square magnitude is then or equal to zero we are going to return otherwise we are going to rotate our and rotate our player right so our aim is to move our forward player forward a forward direction to the input direction right so there is a a very simple method on energy is called like uh bar start get direction equals to option code Dot it's called Uh Vector tree dot rotate towards which will take our controller dot forward uh transform the transform that forward then our Target to movement Direction and also take another input for like rotation rotation speed into time to Delta time so we can control our rotation speed okay and lastly 0.0 f so what Vector 3 what it was does is like rotate our uh it rotates our character controller transform that forward our this direction to our input Direction with this speed and angle between them can be maximum to zero f okay now we are going to first we need to declare it to just copy it and paste it here now we're going to rotate our character towards our Target direction right so character controller and not this one controller transform the rotation equal to quaternal quaternion Loop rotation yep so Target Direction so now we should be able to rotate our characters too okay so let's give us like say 10. if you play it right now you see our character is rotating nice also we um yep yeah it's working yeah it's looking weird that because the idle animation is is weird Okay so now let's fix this okay what do we want to do is when our movement direction is zero we want to set our animation stick to idle okay first we need public animator player any matter okay then we are going to set Bull Run false and then if it's not then we're going to show okay so we are using run that because you can see it has a run variable and the condition you can see run through and run false okay now if first we have to assign the variables okay so assign our variables here from Stickman here you see it's working perfectly and it doesn't look weird okay sour character josti movement is done but one thing is that our our camera is not following okay camera is not following that's a bummer because we want to like um we want our camera to follow the player right so for this purpose you can use a custom script but I'll be using unity's which is called cinemasion yeah I think it's cool cinemation is actually cool to be honest you can do a lot of the stuff with it then this is our main camera right okay let's hit import ant [Music] yeah got imported then we are going to use create a cinemation camera virtual camera and call it uh Hollow camera so it will follow character right we don't want so let's use the settings first it will follow follow which will follow our character and composite to nothing and we want to bending mode 2 wall space okay now we have to adjust our camera position so here uh to like seven from seven to nine and let's say five well no five is too much okay then we want to okay now this angle seems good maybe more no no no more here okay now that's it our camera follower is done uh if you if you play it right now you should follow our character you see yeah it's also uh from the scene you can see that our uh follow camera as a damping you see it's it's smooth transition but let's say if you don't want it uh you can also change it from here damping to zero but you see now there is no but I want to keep it that's because I like it okay that's it for today guys if you have any questions or need further assistance please feel free to leave a comment below don't forget to like this video And subscribe to the channel I'll see you guys in the next video
Info
Channel: Game Cipher
Views: 12,704
Rating: undefined out of 5
Keywords: joystickgr, joystick gr, joystick.gr, Joystick Mobile, Mobile Joystick, HYper Casual Joystick, Cinemachine, Character Animation, AnimatorController, Unity, Unity2D, Unity3D, Unity Programming, Unity Game Design, 3D environment, Game Design, Game Development Tips, Unity3DTutorial, Gameing, VideoGames, MobileGames, PcGames, GameDesign, GameArt, GameIndustry, GameDev, GameDesignTips, Fps, GameDevCommunity, HyperCasual, HybridCasual Movement, HybridCasual, Pc Joystick, UnityTutorial, Unity3DTutoiral, joystick
Id: sYDq5s1EXiI
Channel Id: undefined
Length: 15min 52sec (952 seconds)
Published: Wed Jun 07 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.