Unity3D/2D: Mobile Touch Controls - Moving a Character from Left to Right

  Рет қаралды 109,156

Waldo

Waldo

Күн бұрын

Пікірлер: 250
@oneleaf525debnitya6
@oneleaf525debnitya6 4 жыл бұрын
Viewed so many tutorials and only this one worked. Thnx Man Great Stuff
@georgeoutters5657
@georgeoutters5657 6 жыл бұрын
Awesome video, exactly what I needed for my small project!
@ArikCool
@ArikCool 3 жыл бұрын
Please Help! How can you make the character not glide? i want it to move while pressing and immediately stop while not moving
@ast4ay479
@ast4ay479 2 жыл бұрын
Increase the drag on the rigidbody i havnt used 2d but with 3d thats what i did in 3d
@matteoxt24mt
@matteoxt24mt 4 жыл бұрын
Where is the part when u connect the code to the button?
@amit_patel168
@amit_patel168 6 жыл бұрын
Nice trick dude... This helped me🙂
@jbsoftware3720
@jbsoftware3720 6 жыл бұрын
Thanks, i will remember to make a donation after.
@moroniafrifa614
@moroniafrifa614 6 жыл бұрын
Thanks a lot for this. Saved me from a headache
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
Moroni Afrifa cheers
@TheRitesh41
@TheRitesh41 4 жыл бұрын
AAAH life saver video thanks man i was trying to figure that out , somehow i couldnot figure out the simple logic of dividing by screen width to manage the multi touch . THANKS AGAIN.
@siuchoi7655
@siuchoi7655 5 жыл бұрын
Thanks a lot! That is exactly what I need for my game! Great tutorial!
@CanCaglaAndMina
@CanCaglaAndMina 5 жыл бұрын
Thank you so much. I was strugling with this problem for a week, but your vid helped, so thanks!!!
@ics_de
@ics_de 6 жыл бұрын
Why do you have such a low subscribers number? Your explanations are pretty good and clear! I hope your channel grows, because you deserve it :)
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
Thanks for the kind words! I've only been doing this for a couple of months. Things will hopefully grow at an exponential rate, but please share and spread the word to help me out along the way. :)
@ics_de
@ics_de 6 жыл бұрын
As Told By Waldo That's what I'll do!
@pedidosnica
@pedidosnica 2 жыл бұрын
Thanks, I was seeking this.
@hyperlaserstudios7893
@hyperlaserstudios7893 6 жыл бұрын
Can you please make another one of these, but for 3D?
@SamGaming360
@SamGaming360 5 жыл бұрын
Did you ever find out how?
@morenunomath9562
@morenunomath9562 5 жыл бұрын
@@RichOrignisl I am starting to study c#, and I did what you recommended and it worked but the character is very slow, I've already I increased the speed of the character and it still slow, can you help me?
@laele2726
@laele2726 5 жыл бұрын
​@@morenunomath9562 try to change the physics properties from your character game object
@charlesferry9465
@charlesferry9465 4 жыл бұрын
@@RichOrignisl should I change Vector2 to Vector3??
@NewtonPL
@NewtonPL 4 жыл бұрын
you know you can edit the script?
@christianthompson1839
@christianthompson1839 6 жыл бұрын
So my question is how do we implement both keyboard controls and touch controls for people with touchscreen computers? I was thinking maybe you could use *else if* but I'm not sure
@wchannel01
@wchannel01 6 жыл бұрын
I tried to use this for a 3D game which uses "a" and "d" to move left and right but could not successfully replace the keys with the mobile input. This is what I have: void FixedUpdate() { rb.AddForce(0, 0, forwardForce * Time.deltaTime); if(Input.GetKey("d")) { rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange); } if (Input.GetKey("a")) { rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange); } }
@DionFernandes3
@DionFernandes3 4 жыл бұрын
Here's the code for 3D using System.Collections; using System.Collections.Generic; using UnityEngine; public class Movement : MonoBehaviour { //variables public float moveSpeed = 300; public GameObject character; private Rigidbody characterBody; private float ScreenWidth; // Use this for initialization void Start() { ScreenWidth = Screen.width; characterBody = character.GetComponent(); } // Update is called once per frame void Update() { int i = 0; //loop over every touch found while (i < Input.touchCount) { if (Input.GetTouch(i).position.x > ScreenWidth / 2) { //move right RunCharacter(1.0f); } if (Input.GetTouch(i).position.x < ScreenWidth / 2) { //move left RunCharacter(-1.0f); } ++i; } } void FixedUpdate() { #if UNITY_EDITOR RunCharacter(Input.GetAxis("Horizontal")); #endif } private void RunCharacter(float horizontalInput) { //move player characterBody.AddForce(new Vector2(horizontalInput * moveSpeed * Time.deltaTime, 0)); } }
@MaxAttack78
@MaxAttack78 4 жыл бұрын
SHADY thank you so much for the help! I got the coding down now would I follow the rest of the steps in the vid or no
@DionFernandes3
@DionFernandes3 4 жыл бұрын
@@MaxAttack78 Yes you can
@MaxAttack78
@MaxAttack78 4 жыл бұрын
SHADY ok thanks so much you quite literally saved my game 😂
@zKingRox
@zKingRox 4 жыл бұрын
@@MaxAttack78 did it work for you when you played the game on phone
@giorgiphareshishvili
@giorgiphareshishvili 4 жыл бұрын
Thanks bro, you really helped me, when i release my game ill post the link here so people can rate it
@NewtonPL
@NewtonPL 4 жыл бұрын
so that was a lie
@riodsh6186
@riodsh6186 6 жыл бұрын
I love you for this TuT Sir this helped me a lot !
@claudiu7897
@claudiu7897 5 жыл бұрын
how do i flip the character
@hrva0073
@hrva0073 4 жыл бұрын
Can you make sprite flip left and right with this script?
@gidothings8256
@gidothings8256 4 жыл бұрын
Hrva 007 yes, with an animator
@memefish9772
@memefish9772 3 жыл бұрын
still working with the 2021.1 version. thanks, you get a new subscriber :)
@diazcastro7331
@diazcastro7331 3 жыл бұрын
didnt work for me
@leanderpereira5257
@leanderpereira5257 6 жыл бұрын
Can u make a similar video for moving a character up and down
@guilhermelopes2587
@guilhermelopes2587 5 жыл бұрын
@@lachzloyt9189 What?
@NewtonPL
@NewtonPL 4 жыл бұрын
just change the script
@JonBaldockInkDrawings
@JonBaldockInkDrawings 3 жыл бұрын
i tried changing thescript for up and down, doesn't work
@user-dd5gk9qj9g
@user-dd5gk9qj9g 6 жыл бұрын
so was the ui buttons solely for aesthetic reasons, for the highlighting and the "L" and "R" text??
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
Sam Smith yes
@cjthomp2005
@cjthomp2005 6 жыл бұрын
waldo, theres no point in doing that if the buttons dont do anything.
@shoaibmujawar1375
@shoaibmujawar1375 6 жыл бұрын
That's exactly what I needed. Thanks a lot...
@Asherrr
@Asherrr 5 жыл бұрын
Absolutely fantastic video, you really "touched" on exactly what I needed! XD
@hddbvdcx
@hddbvdcx 2 жыл бұрын
Hey This is supercool! You helped me a lot.
@FatherPhi
@FatherPhi 5 жыл бұрын
Great idea man, awesome content
@Bartosz25
@Bartosz25 6 жыл бұрын
Great tutorial, thank you.
@djalaljay
@djalaljay 3 жыл бұрын
You saved my Game thank you
@TheUnOrdinaryFreak
@TheUnOrdinaryFreak 6 жыл бұрын
3:18 when you click on the buttons it highlights but in my project that is in 3D when i hit the button it doesn't highlight. Is there any problem?
@pressstart6864
@pressstart6864 6 жыл бұрын
Make sure you have an event system added to your scene. They're usually added automatically when you add a canvas, but if you don't have it, that could be the reason for the problem. 3D shouldn't be a problem.
@TheUnOrdinaryFreak
@TheUnOrdinaryFreak 6 жыл бұрын
@@pressstart6864 please if you could make a 3D tutorial for the same it would help a lot of people !
@leezakdev
@leezakdev 5 жыл бұрын
Just add a new canvas and it should fix your problem
@saudahmad1429
@saudahmad1429 6 жыл бұрын
thank you for this tutorial.
@ahsanarifeen7827
@ahsanarifeen7827 3 жыл бұрын
Hey Waldo, I wanted to ask if the touch input works in the editor, or will we have to build the project first? I subscribed :)
@Slinkingcheeze
@Slinkingcheeze 5 жыл бұрын
Hi, great video dude! I have a question though, is there a way to make the character instantly stop moving as soon as i lift my finger from the screen? So the character doesn't start gliding in that direction?
@2014-b4o
@2014-b4o 4 жыл бұрын
yes by using transform.Translate instead of AddForce
@atch300
@atch300 3 жыл бұрын
@@2014-b4o hey thanks. Works like a charm
@SamGaming360
@SamGaming360 5 жыл бұрын
Anybody know how to make this in 3d games?
@SamGaming360
@SamGaming360 5 жыл бұрын
@@pavinpariyar1883 ok thanks
@carnage6968
@carnage6968 5 жыл бұрын
@@pavinpariyar1883 Could you copy/paste it in a comment ,please? I don't know where I messed up x)
@aryanjumani4524
@aryanjumani4524 5 жыл бұрын
@@pavinpariyar1883 also you need three values in the vector3, X, Y, and Z and not just X and Y values
@japrolol
@japrolol 5 жыл бұрын
Is it possible for me to make it that if i stop holding my character pauses, please answers!
@BillyMan
@BillyMan 5 жыл бұрын
Thank you, Sir. You helped me
@VoiD90009
@VoiD90009 2 жыл бұрын
Ui buttons work in editor but they do not work in android after building it
@babatelli8766
@babatelli8766 7 жыл бұрын
nice tutorial mate, really helped me out. would be nice if u could do a series on how to build a simple android game with unity. maybe a endless runner or something.
@AsToldByWaldo
@AsToldByWaldo 7 жыл бұрын
Thanks. I am currently working on a series. Stay tuned!
@babatelli8766
@babatelli8766 7 жыл бұрын
any date u gonna release the first episode?
@AsToldByWaldo
@AsToldByWaldo 7 жыл бұрын
I'm recording the first episode this week so most likely next week. Since I'm going to cover a lot of topics from start to finish over a series of videos, it might be a few weeks before I cover anything substantial. Make sure to subscribe for updates on when this will be released.
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
A little earlier than planned. Episode 1 is done. kzbin.info/www/bejne/nomxioCjbcxgh7M
@letsplaynay9936
@letsplaynay9936 4 жыл бұрын
What if its isometric? I have diaganol movements aswell
@aiman9306
@aiman9306 4 жыл бұрын
code for 3D pls?
@AdirBenYair97
@AdirBenYair97 5 жыл бұрын
Thanks man this really helped!
@ebbevandijk8069
@ebbevandijk8069 5 жыл бұрын
You’re the real mvp
@2420-y2o
@2420-y2o 6 жыл бұрын
Thank you. Splendid.
@latikerostv1556
@latikerostv1556 6 жыл бұрын
Excellent tutorial! I've done everything and made my character move from left to right. May I ask, how to move a character from top to bottom? Will give make a youtube tutorial for it?
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
It's rather simple actually. Just change a few things in the code to use the ScreenHeight, and Y axis. Here is what the code would be modified (didn't test it, but it should work fine): dotnetfiddle.net/kMPyQg
@ondrejbenes2297
@ondrejbenes2297 6 жыл бұрын
Thank you for this tutorial. I have just started developing simple games, for Android mainly, and I am still getting into it but I have so many ideas. I needed this bit of code for one of my game and could not find a proper tutorial or explanation that would fit my needs. Your video is nice and simple and code well presented, good job and THANK YOU. I leave like and subscribe, hope that helps.
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
Ondřej Beneš I appreciate your support
@maliktot7182
@maliktot7182 3 жыл бұрын
What i have to do to make my character move like to the bottomleft or bottomright?
@umuttarlan5541
@umuttarlan5541 4 жыл бұрын
I tried this codes with "transform.turnaround" butit dosent work. Do you know how can ı make this. If you answer you will help a lot.
@raydartt
@raydartt 6 жыл бұрын
Thanks for the video. You are right there aren't many videos on touch controls. It works great but I was surprised to find that the tilt also works. I thought you had to use the Accelerometer for that to work. I don't want my player moving except by screen touch. How can i stop that? Thanks
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
There's nothing in the code that should make that happen. You might have something else enabled causing it to do that.
@raydartt
@raydartt 6 жыл бұрын
Thanks for your response. I found the problem. I had another script attached to the player that i was using to test the Accelerometer. I remember deleting it but i guess i didn't save my scene before i tried your script. Sorry to bother you with my stupidity.
@martinovlog
@martinovlog 3 жыл бұрын
But i cant add a pause button now, does anyone know how to solve this?
@brandonisjerimaya6296
@brandonisjerimaya6296 5 жыл бұрын
AMAZING! but.... What alterations to the code are necessary to attach the script to the player instead of the camera?
@ЯрославЗинченко-ц4ш
@ЯрославЗинченко-ц4ш 6 жыл бұрын
I don't get it. You're assigning your script to your Main Camera and trying to access the rigidbody of the character, but his rigidbody is set to 'private'. How is it even working?
@dimwood2011
@dimwood2011 6 жыл бұрын
I think because he declared it in the Start() function Start() { characterBody = character.GetComponent(); }
@wzykz7139
@wzykz7139 4 жыл бұрын
Hey great video! Just wondering how to get character object to stop sliding?
@2014-b4o
@2014-b4o 4 жыл бұрын
by using transform.Translate instead of CharacterBody.AddForce
@Zaine7673
@Zaine7673 6 жыл бұрын
Excellent Tutorial brother, thank you. I loved the fact that you don't have to clutter the screen with UI elements for simple move functions on a mobile. I've used parts of this for a 2.5D game I'm working on (hope you don't mind) I'm using rigidbody.velocity to move my character but he seems to slide for a while after i let go of the screen. have to figure that one out. I have a charge jump feature (hold jump for longer to do a higher jump) for PC at the moment. would love to see you do a video on how to do this on a mobile maybe using double tap? thanks,
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
Appreciate the feedback! Feel free to use everything in this video, that's why I made it. :) Rigidbody.velocity is still the best way to move a character, but adjust the gravity and linear drag on the character to fix the sliding. You'll also have to adjust the moveSpeed variable along with it since increasing these will make him move slower. It takes a while to find the right setting that works best for your game. I recently had this problem with a new game I am working on, but after a few minutes of tinkering I was able to get it right. Down the road I'll be making more videos, but for mobile jump, what I've done in the past is use the first half of the screen for Left/Right controls and then the second half touch for jump. That can easily be done using the code in this video, but instead of dividing screen width / 2, change it to / 4 (quarter of the screen). Cheers!
@jonyp2266
@jonyp2266 4 жыл бұрын
my character is disappearing with this script when i add it to main camera
@N1thium
@N1thium 5 жыл бұрын
Hey Waldo nice video! There is a way to make it without make the character be a game object of the camera? thanks!
@greeng448
@greeng448 3 жыл бұрын
Amazing
@79rooky
@79rooky 5 жыл бұрын
With the touch controls, how do you flip the sprite when it goes left and right? I tried other tutorials but they're all for keys and not touch and all their code doesn't work
@ajaysrinivas3819
@ajaysrinivas3819 4 жыл бұрын
THANKS A BUNCH MAN😘🙌
@arvindersingh6593
@arvindersingh6593 4 жыл бұрын
Amazing, Thank you
@photoshopsuraj
@photoshopsuraj 6 жыл бұрын
How to make this in 3D its not working
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
Should work in 2D or 3D
@christianthompson1839
@christianthompson1839 6 жыл бұрын
Yup
@SamGaming360
@SamGaming360 5 жыл бұрын
@@AsToldByWaldo I try to assign the 2drigidbody but it doesn't work on 3d
@markushoffmann3494
@markushoffmann3494 2 жыл бұрын
You just Gained a Sub, Like and Comment really good vid btw. awesome 🤩
@lordvir-clashofclansandmor5436
@lordvir-clashofclansandmor5436 6 жыл бұрын
Debug.Log ("i am new to programming and still learning c#.. Can you help with a script for the same left-right functions but in 3d? please?")
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
Working on it
@lordvir-clashofclansandmor5436
@lordvir-clashofclansandmor5436 6 жыл бұрын
As Told By Waldo okk!! I subbed you!
@lordvir-clashofclansandmor5436
@lordvir-clashofclansandmor5436 6 жыл бұрын
As Told By Waldo is it ready bro??
@lordvir-clashofclansandmor5436
@lordvir-clashofclansandmor5436 6 жыл бұрын
why dont u tell?? is it ready??? please help me
@lordvir-clashofclansandmor5436
@lordvir-clashofclansandmor5436 6 жыл бұрын
tell is it ready? it dosnt take 2 days for a script to be ready!
@MobileGames-GamePlays
@MobileGames-GamePlays 6 жыл бұрын
Hello. Very good video! Thnks! But :( My script does not have a "RunCharacter" style function. Instead of using "panelim.transform.Rotate (0, 0, turnSpeed * Time.deltaTime);" I use a code like. What should I write in fixedUpdate to be able to experiment in the Unity Editor? Can you help me?
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
Choco Like instead of using run character I would use that line. For left side of the screen just negate turnspeed like this -turnSpeed. If you send me an email with your script I can show you what I mean.
@MobileGames-GamePlays
@MobileGames-GamePlays 6 жыл бұрын
My script is below. (I could not find your mail address) using UnityEngine; public class movement : MonoBehaviour { public float turnSpeed = 15f; public GameObject panelim; private float ScreenWidth; void Start () { ScreenWidth = Screen.width; } void Update () { int i = 0; while (i < Input.touchCount) { if (Input.GetTouch(i).position.x > ScreenWidth / 2) { //right panelim.transform.Rotate(0, 0, - turnSpeed * Time.deltaTime); } if(Input.GetTouch(i).position.x < ScreenWidth / 2) { //left panelim.transform.Rotate(0, 0, turnSpeed * Time.deltaTime); } ++i; } } private void FixedUpdate() { #if UNITY_EDITOR // ????????????? #endif } }
@MobileGames-GamePlays
@MobileGames-GamePlays 6 жыл бұрын
My email is chocolikegames@gmail.com . Pls help for this. Thnks.
@dnt_dimpsybeast7230
@dnt_dimpsybeast7230 6 жыл бұрын
@@MobileGames-GamePlays yo bro got the sam problem can u help me? or send me the code plz
@MobileGames-GamePlays
@MobileGames-GamePlays 6 жыл бұрын
@@dnt_dimpsybeast7230 I haven't found a solution on Unity editor. I added 2 Buttons instead of using the unity editor. I also commanded these buttons to work in update mode. I thought it was a component except for the Button component. That's how I solved my problem. Let me leave the link to my game. I'd appreciate it if you'd give it 5 stars. play.google.com/store/apps/details?id=com.Chocolikegames.space.ball.thiefs.action.adventure.high.speed.ball.casual.best.indie.jump.star.game.games.rotaw.rotate.wars
@varundoshi5136
@varundoshi5136 3 жыл бұрын
This isnt working for me...cant figure out why
@2014-b4o
@2014-b4o 4 жыл бұрын
when i click on my pause button my player moves cuz of the screen width how can i fix it
@martinovlog
@martinovlog 3 жыл бұрын
Did you find a solution?
@syympl257
@syympl257 3 жыл бұрын
I did everything as you said and did , but it didn't work neither with touch nor with the keyboard , i've spent my entire day watching videos and learning code so that i can move my object just left and right on mobile screen by touch , but still haven't found any success
@nachohernandez9330
@nachohernandez9330 4 жыл бұрын
In a 3D game I should declare a Rigidbody3D instead?
@marcialdavidgamerpineda8374
@marcialdavidgamerpineda8374 4 жыл бұрын
Yep
@reasorr
@reasorr 4 жыл бұрын
How can I make it more precise so that the player doesn't slide that hard ?
@2014-b4o
@2014-b4o 4 жыл бұрын
add transform.tanslate instead of CharacterBody.Addforce in the movement or what ever u named ur rigid body
@2014-b4o
@2014-b4o 4 жыл бұрын
and edit the values
@boismd
@boismd 6 жыл бұрын
nice video sir .. can i ask if this can be used to tilting movement so it can move whenever i press left side or right side of screen continually? thx
@knockknockp
@knockknockp 5 жыл бұрын
Can't you just use for loop in the script instead of that while loop? anyways thanks for helpful vid
@nrgstudios612
@nrgstudios612 5 жыл бұрын
I think so. You got the initialization, condition and increment right there.
@HeartThief04
@HeartThief04 4 жыл бұрын
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Movement : MonoBehaviour { //variables public float moveSpeed = 300; public GameObject character; private Rigidbody2D characterBody; private float ScreenWidth; // Use this for initialization void Start () { ScreenWidth = Screen.width; characterBody = character.GetComponent(); } // Update is called once per frame void Update () { int i = 0; //loop over every touch found while (i < Input.touchCount) { if (Input.GetTouch (i).position.x > ScreenWidth / 2) { //move right RunCharacter (1.0f); } if (Input.GetTouch (i).position.x < ScreenWidth / 2) { //move left RunCharacter (-1.0f); } ++i; } } void FixedUpdate(){ #if UNITY_EDITOR RunCharacter(Input.GetAxis("Horizontal")); #endif } private void RunCharacter(float horizontalInput){ //move player characterBody.AddForce(new Vector2(horizontalInput * moveSpeed * Time.deltaTime, 0)); } }
@brayliodeus5922
@brayliodeus5922 7 жыл бұрын
nice tutorial, more pls :)
@AsToldByWaldo
@AsToldByWaldo 7 жыл бұрын
Braylio Deus thank you :) more coming soon
@tylersanders6992
@tylersanders6992 4 жыл бұрын
Just a question this is probably to old but how would I make it without press and hold)
@gamethingstuff
@gamethingstuff 4 жыл бұрын
How would you had exceptions to this. Like if you wanted to press a button on screen without it causing player movement aswell?
@gamethingstuff
@gamethingstuff 4 жыл бұрын
Never mind solved it :) if(Input.GetTouch(i).position.y > ScreenHeight / 4.5) used that so it would cover the top 4.5/5ths of the screen so the bottom section would not be included so i could buttons in there.
@2014-b4o
@2014-b4o 4 жыл бұрын
@@gamethingstuff it didnt work
@gamethingstuff
@gamethingstuff 4 жыл бұрын
@@2014-b4o my script if it helps using System.Collections; using UnityEngine; using UnityEngine.UI; public class PlayerMovement : MonoBehaviour { public Rigidbody rb; public float forwardForce = 6000f; public float sidewaysForce = 30f; private float ScreenWidth; private float ScreenHeight; void Start() { ScreenWidth = Screen.width; ScreenHeight = Screen.height; } void FixedUpdate() { if(rb.position.y < -1f) { FindObjectOfType().EndGame(); } int i = 0; rb.AddForce(0, 0, forwardForce * Time.deltaTime); while(i < Input.touchCount) { if(Input.GetTouch(i).position.y > ScreenHeight / 4.5) if(Input.GetTouch(i).position.x > ScreenWidth / 2) { rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange); } if(Input.GetTouch(i).position.y > ScreenHeight/ 4.5) if(Input.GetTouch(i).position.x < ScreenWidth / 2) { rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange); } ++i; } } }
@2014-b4o
@2014-b4o 4 жыл бұрын
@@gamethingstuff thanks i will read it tomorrow
@2014-b4o
@2014-b4o 4 жыл бұрын
@@gamethingstuff what if i wanted to put buttons in the upper side what is the values for that
@MINECRAFTzerack
@MINECRAFTzerack 5 жыл бұрын
Nice tutorial but how can i code it that if I stop pressing the button that the character INSTANTLY stops to move?
@blackjackveteran
@blackjackveteran 4 жыл бұрын
did you figure it out dealing with the same problem
@2014-b4o
@2014-b4o 4 жыл бұрын
add transform.tanslate instead of CharacterBody.Addforce in the movement or what ever u named ur rigid body
@2014-b4o
@2014-b4o 4 жыл бұрын
and edit the values
@roemerlin9887
@roemerlin9887 3 жыл бұрын
@@2014-b4o I don't get it, what do you mean
@ayourabbu
@ayourabbu 5 жыл бұрын
my character move very slowly????
@aryansinha7207
@aryansinha7207 4 жыл бұрын
for some reason, my UI won't show up in the game screen PLZ HELP
@2014-b4o
@2014-b4o 4 жыл бұрын
have u added them to ur canvas?
@2014-b4o
@2014-b4o 4 жыл бұрын
try adding another canvas too but dont put anything in it and keep ur main canvas
@gamethingstuff
@gamethingstuff 4 жыл бұрын
thank you my man
@MINECRAFTzerack
@MINECRAFTzerack 5 жыл бұрын
I have the same code like you but i get this error: MissingReferenceException: The object of type 'Rigidbody2D' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object.
@ZeoGundam
@ZeoGundam 6 жыл бұрын
hey I have a question I hope you can answer for me. So Ive implemented this code where the left side of the screen jumps and the right side of the screen does a dash, but when I dash I also jump as well. Is there anyway that can be fixed? Thank you for reading this and I look forward to your response :)
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
JJWrekinCrew separate your jump code and your dash code. If you email me your source code I can be more specific.
@ZeoGundam
@ZeoGundam 6 жыл бұрын
Alrite cool thank you for doing this! What is your email?
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
Please go through my website.
@ZeoGundam
@ZeoGundam 6 жыл бұрын
Thanks again for the help! Ive subscribed to your channel and looking forward to your next videos!
@gooty6185
@gooty6185 4 жыл бұрын
excuse can we use unity buttons in mouvement smoothly I mean when I put in the left button the object move to the left smoothly not translate +1 and stopped I mean that have you got an idea about making buttons useful to move in android not this bad method in the video no an other one please
@2014-b4o
@2014-b4o 4 жыл бұрын
maybe u have to add rigid body and force
@poojanarendiran6052
@poojanarendiran6052 6 жыл бұрын
can u plz say how did u link those animation with the left and right button? I actually want if I press left button my character needs to jump and if I press right button my character need to fire. plz give me a solution as soon as possible.
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
The buttons we created on the screen were just for visual purposes only. The reason for this is we were not able to do a press and hold function which would work best for moving left and right. Instead we coded a IF touch is on screen, then loop and based on the position we decided whether it was on the left or right of the screen (see source code above). In your case, you would benefit from attaching a function to the UI buttons themselves. That can be done in the UI in the inspector, or through code like so: public Button yourButton; void Start() { Button btn = yourButton.GetComponent(); btn.onClick.AddListener(TaskOnClick); } void TaskOnClick() { Debug.Log("You have clicked the button!"); } docs.unity3d.com/ScriptReference/UI.Button-onClick.html Then create two functions, one to fire and one to jump and apply them to your buttons.
@poojanarendiran6052
@poojanarendiran6052 6 жыл бұрын
thanks a lot for the response...ill try and let u know the progress.so kind of u.
@johncarloabad6877
@johncarloabad6877 6 жыл бұрын
but ive already done it. and it doesnt work on my phone ? what will i do for us to play it on mobilephone?
@aimbedarf
@aimbedarf 4 жыл бұрын
Could someone tell me what to change to use the same buttons for up and down?
@2014-b4o
@2014-b4o 4 жыл бұрын
use y instead of x
@KxiiiNG
@KxiiiNG 6 жыл бұрын
THANK YOU! I have been up since 10:3Oam and it is now 5pm. You are the ONLY Helpful tutorial for this as simple as it should seem. I have only 1 issue. Are we not using 'on button click' events? I uploaded to mobile and it highlights when I touch, but my Rigidbody doesn't actually move. However, this is still amazing and it put me in the right direction and I like figuring these things out since I'm new.
@philseitig
@philseitig 5 жыл бұрын
What do I have to change if I only have 20% buttons left and right? It seems not to be: ... ScreenWidth divided by a higher number
@romeosreadings
@romeosreadings 4 жыл бұрын
Thanks this helped :D
@Sixty969-6
@Sixty969-6 5 жыл бұрын
Cantt add script i copied the script from you site but it cant Add?????
@Nasser_Moahammed
@Nasser_Moahammed 3 жыл бұрын
Thanks a lot man
@manojumaeku
@manojumaeku 4 жыл бұрын
Please advice. How do i move the block along with my finger movement, only when i am touching on it? I do not want to move the block automatically to the position of touch in the screen. I am using unityEngine.Touch.
@gametechy702
@gametechy702 4 жыл бұрын
You got a sub dude!
@alexgunzz
@alexgunzz 5 жыл бұрын
I’m trying to figure out how to just move my player character left and right. I don’t want two buttons tho. I just want the player to my left and right by movement of my thumb. Like touch and hold, and move left and right (while holding thumb down) to move the player. Can anyone help? Thanks
@coleseph5321
@coleseph5321 3 жыл бұрын
I keep getting an index out of bounds error when running my script based on this tutorial, can anybody help?
@asemalkameltechnology6871
@asemalkameltechnology6871 6 жыл бұрын
hi man i want to move my player animation with ui button like walk anim i do it with keyboard key but i cant do it with ui button i real need hellp plz
@surjakantasingh3377
@surjakantasingh3377 5 жыл бұрын
You made this looks difficult with your own solitary logic
@anshikatiwari2785
@anshikatiwari2785 4 жыл бұрын
You speak like What I am doing with my life Btw nice tutorial
@tonax2008
@tonax2008 4 жыл бұрын
thanks , you save me c:
@robertoiiasistores5309
@robertoiiasistores5309 3 жыл бұрын
Amazing but I need a tutorial for Vertical like up and down characters
@yoonbin31
@yoonbin31 6 жыл бұрын
You r da best bro
@munirajanm4311
@munirajanm4311 6 жыл бұрын
I have also Copy pasted your Script. Now i can move with arrows. but Still I can not move object by touch the screen. and also you didn't show move with touch.why? Could you please help me?
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
Are you testing touch on mobile device? I show touch in the first 10 seconds of the video. It won't work if you click on the screen with the mouse. For that you need to implement "Input.GetMouseButtonDown(0)". Also make sure you set your project settings to work only with landscape mode. If you open the App in Portrait mode and then rotate to landscape mode, the controls won't be in the right position. Hope that helps.
@munirajanm4311
@munirajanm4311 6 жыл бұрын
Thank you for your suggestion.
@thoriqanwar5882
@thoriqanwar5882 6 жыл бұрын
Are this can used for Vector 3 / 3D object?
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
Yes, if you only want to move left and right. But I assume in a 3D environment, you'd want to be able to move left, right, forward and backwards which would incorporate the X & Z coordinates. You would need to modify the .addForce to use Vector3 and use moveSpeed with add values to each of those coordinates, instead of just the X coordinate, depending on button pressed. Then you would need to create two more buttons for forward and backwards (if on mobile). A joystick might be a better use. Hoping to making a video demonstrating that soon, so make sure to subscribe.
@thoriqanwar5882
@thoriqanwar5882 6 жыл бұрын
As Told By Waldo can you create a tutorial like that please ?
Unity3D/2D: Mobile Joystick Tutorial [NO PLUGINS]
10:17
Waldo
Рет қаралды 96 М.
TOUCH CONTROLS in Unity!
16:09
Brackeys
Рет қаралды 1,3 МЛН
🎈🎈🎈😲 #tiktok #shorts
0:28
Byungari 병아리언니
Рет қаралды 4,5 МЛН
Жездуха 41-серия
36:26
Million Show
Рет қаралды 5 МЛН
I Made the Same Game in 8 Engines
12:34
Emeral
Рет қаралды 4,3 МЛН
I Redesigned the ENTIRE YouTube UI from Scratch
19:10
Juxtopposed
Рет қаралды 1 МЛН
How to use TOUCH with the NEW Input System in Unity
24:11
samyam
Рет қаралды 76 М.
Simple Touch Controls in UNITY without any Code
6:11
The Game Guy
Рет қаралды 34 М.
Making an IOS/Android game in UNITY - Beginner Tutorial - #1
8:49
Blackthornprod
Рет қаралды 770 М.
Pinch to Zoom and Panning on Mobile in Unity
8:00
Waldo
Рет қаралды 75 М.
Quickly preview your game on Android device | Unity tutorial
6:29
🎈🎈🎈😲 #tiktok #shorts
0:28
Byungari 병아리언니
Рет қаралды 4,5 МЛН