Thank you, I have been searching for a video on basic movement that doesent assume the person already has everything set up for ages. Keep upp the good work
@@AviyaleTales i managed to follow along and get the script to work even thoug i had absolutely no experience using unity at the time so id say its pretty beginer friendly
@@justapersonontheinternet brooo this is so cool seeing you here from a year ago and now. Bruhhhh how’s your progress? I’m currently a beginner in using unity! So how does it feel having been using this software for over a year now?
Unity had a little update on their API, this current code didn't exactly worked for me but here's what I've found on the Unity's documentation and it might help someone else: using System.Collections; using System.Collections.Generic; using UnityEngine; public class CharController : MonoBehaviour { public float _speed = 5f; // Start is called before the first frame update void Start() {
} // Update is called once per frame void Update() { var _move = Input.GetAxis("Horizontal"); transform.position = transform.position + new Vector3(_move * _speed * Time.deltaTime, 0, 0); } } The main change is in the -> "transform.position = transform.position + new Vector3(_move * _speed * Time.deltaTime, 0, 0); Hope it helps someone :)
Thank you so much. Short and easy to understand. Keep it up. Edit : By the way if anyone needs the code here it is. using UnityEngine; public class PlayerMovement : MonoBehaviour { public float MovementSpeed = 4; public float JumpForce = 1; private Rigidbody2D _rigidbody; private void Start() { _rigidbody = GetComponent(); } private void Update() { var movement = Input.GetAxis("Horizontal"); transform.position += new Vector3(movement, 0, 0) * Time.deltaTime * MovementSpeed; if (Input.GetButtonDown("Jump") && Mathf.Abs(_rigidbody.velocity.y) < 0.001f) { _rigidbody.AddForce(new Vector2(0, JumpForce), ForceMode2D.Impulse); } } }
This was brilliant, movement is the #1 thing I struggle with and it's so crucial to every game, this literally took me 20 minutes maximum and that was me taking my time with it
I altered the code a bit so the player can also go vertically now but thank you so much for this video it helped a lot :D here is the code if anyone is interested : using UnityEngine; public class movement : MonoBehaviour { public float MovementSpeed = 1; private void Start() {
} private void Update() { var horizontalMovement = Input.GetAxis("Horizontal"); var verticalMovement = Input.GetAxis("Vertical"); transform.position += new Vector3(horizontalMovement, 0, 0) * Time.deltaTime * MovementSpeed; transform.position += new Vector3(0, verticalMovement, 1) * Time.deltaTime * MovementSpeed; } }
Here is the script changed a bit the rotation for it to be correct* using System.Collections; using System.Collections.Generic; using UnityEngine; public class Character2DController : MonoBehaviour { public float MovementSpeed = 1; public float JumpForce = 1; private Rigidbody2D _rigidbody; private void Start() { _rigidbody = GetComponent(); } private void Update() { var movement = Input.GetAxis("Horizontal"); transform.position += new Vector3(movement, 0, 0) * Time.deltaTime * MovementSpeed; if (Input.GetButtonDown("Jump") && Mathf.Abs(_rigidbody.velocity.y) < 0.001f) { _rigidbody.AddForce(new Vector2(0, JumpForce), ForceMode2D.Impulse); } Vector3 charecterScale = transform.localScale; if (Input.GetAxis("Horizontal") < 0) { charecterScale.x = -10; } if (Input.GetAxis("Horizontal") > 0) { charecterScale.x = 10; } transform.localScale = charecterScale; } }
You should watch the entire video to understand everything but here is the c# movement script (not the jump one) using System.Collections; using System.Collections.Generic; using UnityEngine; public class Character2DController : MonoBehaviour { public float MovementSpeed = 1; private void Start() {
}
private void Update() { var movement = Input.GetAxis("Horizontal"); transform.position += new Vector3(movement, 0, 0) * Time.deltaTime * MovementSpeed; } } Edit, you need to change the public class to whatever your script name is
This is by far the best Unity 2d tutorial i have came across so far, atfirst i didnt like typing the code cause im lazy but this was very easy, keep up the great work!
Note: if you want to make a level using Tilemaps I don't recommend using that code(For moving right and left) because it will really glitchy so you can use: void Start() { Rb = GetComponent(); } void Update() { float horiz = Input.GetAxisRaw("Horizontal"); Rb.velocity = new Vector2(Speed * horiz, Rb.velocity.y); } so it will not so glitchy.
Thanky you sooo much i have been looking for tutorials for 2 weeks and when I found you I was soo happy because it worked and nothing ever worked for me and again thank you soooo much hope you have a good day!
Figured out the compiler issue. and you should tell people be aware that the "screw driver" icon to the left of the code is there for a reason. it kinda auto corrects coding for you. i was following videos trying to mirror those codes and for some reason the capitalization of certain text was an issue majorly. SO for those seeing confusing compiler issues MAKE SURE you use that screw driver because it will generate the proper text below what you tried code when it comes to capitalization and expression.
BEST BY FAR AWARD*** Brand new to all this and have been search non-stop for guidance having to do with movement that didn't rely on premade scripts. Although not every aspect of the code was explained it became more clear after the results manifested. Anyways great job!
The system is pretty simple and there is no ground detection but it is pretty beginner friendly and it does the job for now Thanks you have just earned yourself a new sub
Hey I don’t agree with your jump system, in the same line you’re checking for a “Jump” input you’re also checking if the y component of our velocity is less than 0.001 (I guess you made this value small enough to kind of simulate when the player is standing) but there are actually 2 situations where our up velocity is close to 0: -when we are standing still on a surface -at the pick of our jump (when we’re about to fall back down) This means that we can still jump infinitely if we press “Jump” just at the right time. Please correct me if I’m wrong! Other than that I think the video is very good :)
You are 100% correct in your observation. This system was chosen deliberately because it is as simple as it gets. There various other ways of detecting when a character is grounded, but all of them are more complex than an absolute-beginner video requires. The same counts for almost all components :)
@@DistortedPixelStudios I am getting error unexpected ';' in script. Can you help me solve that error?? Edit:Fixed the error but, the jump movement itself is not there in playmode
@@DistortedPixelStudios bro i need help when i put camera in my character , character is not turning 180 scale "camera" is turning 180 scale when i eject camera on my character its working but this is the problem if i eject the camera my character is not going with camera and after a while my character disappears from view
Thank you so much! I am starting to learn how to make games and this was the first obstacle; movement and jumping. I looked all over the internet to find the right tutorial. So when I found this one, I didn’t think it would be that good, but it did what I wanted it to do. So thank you!
Thank you for cutting through all the junk and getting straight to it. I am brand new to C# and just needed someone to tell me how to get from point A to point B.
I kid you not, I did this in four minutes compared to the twelve where I was left wondering why my character didn't jump from the other tutorials. Thanks!
Thank you for getting straight quick into the point and not making an hour long video talking about unecessary things, now I actually know how to make movement, thanks!
i really got stuck because i couldn't control the character and i didn't have any errors. then i found out that i didn't put the script on my character. it works really well so thank you :)
This helped me so much! I've tried so many tutorials and this is the only one that worked, I also felt I learned a lot from it that I can use in future, thank you!
in case anyone else needs it, I modified the statement for transform.rotation instead of movement > 0 is movement < 0 if(!Mathf.Approximately(0,_move)){ transform.rotation = _move < 0 ? Quaternion.Euler(0,180,0) : Quaternion.identity; } for me _move is: var _move = Input.GetAxis("Horizontal"); and I copied the comment above by Nislaav that said Unity changed API and followed the tutorial, works like a charm on 2020.3.4f1 :)
Why do I have to use += instead of = for when making the movement? I have tested what happens when u use = and something is defenetly wrong I just dont know why. I also wondered why we use Vector3 instead of Vector2 for the movement.
Hello, I've tried inputting the same, but I end up with the error "Assets/Character2DController.cs(11,9): error CS0019: Operator '*=' cannot be applied to operands of type 'Vector3' and 'Vector3'". How can I fix this?
Hey guys, if there is an error coming that says something about 'jumpforce', change the jumpforce into a number like this = ( 0, 5 ), ıt worked for me. Thank you for this video also
@@gamerbeast7859 the character in my game is a pill and when I put the code in to the player(pill) it says: the script pill movement dose not contain a class derived from unity engne.monobehaviour
For everyone that is stuck at a wall for etc do this: 2D: If you are on 2D and uses Collider2D as collider then go into "Create > 2D > Physics material 2D" and set the Friction & Bounciness to 0 and on your Player colliders set the material to the physics material you just created. 3D: If you are on 3D and uses Collider as collider then go into "Create > Physics material" and set the Static & Dynamic to 0 (Or keep Dynamic to what it is idk) And on the colliders set the material to the physics material you just created. (If its not working try not changing/do change on the Dynamic setting, Or try Friction Combine to Multiply) I work more with 3D then 2D so idk anything about the 3D part :D
My code just doesnt seem to work ): Im not sure if i have a right version of vscode or something the code just doesnt work,i was wathcing brackeys tutorial and it also didnt work.
Thank you so much! It was a short but helpful tutorial. Though there are a few problems, but I think they might be because of a new version. I was having trouble jumping and I changed two things: 1. I changed the if function to "W" instead of "Jump" example: (Input.GetKey(KeyCode.W) 2. I added something to help with the velocity continuing after falling example: void OnCollisionEnter2D(Collision2D collision) { _rigidbody2D.velocity = new Vector3 (0, 0, 0); }
@@monkeypilot Cool! I hope it goes well! If you need more tutorials, I whole-heartedly suggest the Brackeys YT channel. They make super helpful and easy to follow videos!
Hi there! This is a great and simple video, and it is very easy to understand! Thank you very much for making this! If I can make a request: Have you thought about making a video about 2D movement using the new preview input system? It seems really cool, but I can't seem to get a grasp of it...
Thank you for the kind words, We've had our eye on the New Input System for a while, but we have a policy against writing tutorial content for packages still in preview (has not been officially been released). We have a couple devs who have experience working with it though, join our discord and I'm certain they will be more than willing to assist! Here's an Invite link : discord.gg/EVJ2wpt
@@DistortedPixelStudios Thanks! It makes sense not make tutorials about preview packages 😅 But thanks for link to the discord! I'm soon starting a new project, and it looks like the perfect place to ask questions 😄
@@DistortedPixelStudios hey i need help it says that i cant play it till i fix all the errors but visual studios says i have no errors please get back to me, thanks
Thank you so much for making this video! Its so good and very to the point and concise, from now on in my 2D games I am using this character controller!
Great tutorial ! Thank you! I have a question - when try to add the bonus code that adds the transform rotation the character gets very 'thin' when I turn him around - what am I missing?
Got it! After checking the docs for Quaternion.Euler (my intellisense is broken) - I could see that it was taking degrees as input and that I had entered 100 instead of 180 ! Hence my "thin" sprite!
2:08 I know that could be stupid question to some of us but started learning coding in Visual Studio Code, and wan't to ask why when I type transform.p I don't get any help from program like u can see in that time
@@RiaanWalters I'm still not getting thoes helps + I do not have thoes colors as you can see on video, everything look's white and get's me confuse a little bit.
dude , thanks so much for this video the code is excellent: it's easy to understand, very begginer friendly, and works PERFECT' you sir, earned a new sub!
i found your tutorial and this was great.. your code its so simple! i don't need ground check or whatever to determine that my player on ground or not! thanks
Thank you so much for this!!! For anyone wondering why their Visual Studio isn't adding autocompleting the Unity "words" it is because Visual Studio 19 doesn't come with Unity autocomplete, you have to select it. Instead go to tools ---> get tools and features ---> scroll to Game Dev with Unity ---> Modify. THEN in Unity go to edit ---> perferences ---> external tools ---> script editor ---> Visual Studio 19 :) also here is the function using System.Collections; using System.Collections.Generic; using UnityEngine; public class ADD YOUR FILE NAME HERE: MonoBehaviour { public float MovementSpeed = 1; public float JumpForce = 1; private Rigidbody2D _rigidbody; private void Start() { _rigidbody = GetComponent(); } private void Update() { var movement = Input.GetAxis("Horizontal"); transform.position += new Vector3(movement, 0, 0) * Time.deltaTime * MovementSpeed;
Thank you, I have been searching for a video on basic movement that doesent assume the person already has everything set up for ages. Keep upp the good work
But hes not going into detail assuming you have it all figured out
@@AviyaleTales i managed to follow along and get the script to work even thoug i had absolutely no experience using unity at the time so id say its pretty beginer friendly
@@justapersonontheinternet brooo this is so cool seeing you here from a year ago and now. Bruhhhh how’s your progress? I’m currently a beginner in using unity! So how does it feel having been using this software for over a year now?
@@colinhenry3021 I have definetly improved. Still have to look up essentially everything but atleast now i understand why things work the way they do.
I was struggling with this watching other tutorials. This tutorial was perfectly summed up, clean, and well executed. Thank you so much for this!!!
Unity had a little update on their API, this current code didn't exactly worked for me but here's what I've found on the Unity's documentation and it might help someone else:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CharController : MonoBehaviour
{
public float _speed = 5f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
var _move = Input.GetAxis("Horizontal");
transform.position = transform.position + new Vector3(_move * _speed * Time.deltaTime, 0, 0);
}
}
The main change is in the -> "transform.position = transform.position + new Vector3(_move * _speed * Time.deltaTime, 0, 0);
Hope it helps someone :)
sir can u tell me where can i learn basic of c# and can u tell me why we use symbols like ()* etc . and gapes in the code
ty it hepled me!
i use 2019.4. which version is this for?
thanks dude
it work
thanks man, has saved me a lot of work!!
This video is so under-rated! you simple teaching style has helped me so much. Thank you!
INNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNIT!
really helped even big brack couldn't help lol
@@miqdadisbadatgaming2253 true i am coding my first game and this video helps me Thanks
The whole channel is
@@miqdadisbadatgaming2253 he used a third party animation controller so that’s why i didn’t follow it
Thank you so much. Short and easy to understand. Keep it up.
Edit : By the way if anyone needs the code here it is.
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float MovementSpeed = 4;
public float JumpForce = 1;
private Rigidbody2D _rigidbody;
private void Start()
{
_rigidbody = GetComponent();
}
private void Update()
{
var movement = Input.GetAxis("Horizontal");
transform.position += new Vector3(movement, 0, 0) * Time.deltaTime * MovementSpeed;
if (Input.GetButtonDown("Jump") && Mathf.Abs(_rigidbody.velocity.y) < 0.001f)
{
_rigidbody.AddForce(new Vector2(0, JumpForce), ForceMode2D.Impulse);
}
}
}
hippity hoppity your code is now my property
@@Axegarden hahah nice one. Is it working?
@@gloopsee3801 for some reason no but i will figure it out tomorrow
@@gloopsee3801 btw I think there is a extra 2 lines of code at the end of the video he doesn’t show
@@gloopsee3801 works for me! Thanks!
This was brilliant, movement is the #1 thing I struggle with and it's so crucial to every game, this literally took me 20 minutes maximum and that was me taking my time with it
This is like the only one that’s worked solidly. Thank you!
did u not get any errors
I altered the code a bit so the player can also go vertically now but thank you so much for this video it helped a lot :D here is the code if anyone is interested :
using UnityEngine;
public class movement : MonoBehaviour
{
public float MovementSpeed = 1;
private void Start()
{
}
private void Update()
{
var horizontalMovement = Input.GetAxis("Horizontal");
var verticalMovement = Input.GetAxis("Vertical");
transform.position += new Vector3(horizontalMovement, 0, 0) * Time.deltaTime * MovementSpeed;
transform.position += new Vector3(0, verticalMovement, 1) * Time.deltaTime * MovementSpeed;
}
}
All the codes I tried didnt work both from the video and comments.
But yours did. Bless g
@@afiyindev you're welcome :,)
Here is the script changed a bit the rotation for it to be correct*
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Character2DController : MonoBehaviour
{
public float MovementSpeed = 1;
public float JumpForce = 1;
private Rigidbody2D _rigidbody;
private void Start()
{
_rigidbody = GetComponent();
}
private void Update()
{
var movement = Input.GetAxis("Horizontal");
transform.position += new Vector3(movement, 0, 0) * Time.deltaTime * MovementSpeed;
if (Input.GetButtonDown("Jump") && Mathf.Abs(_rigidbody.velocity.y) < 0.001f)
{
_rigidbody.AddForce(new Vector2(0, JumpForce), ForceMode2D.Impulse);
}
Vector3 charecterScale = transform.localScale;
if (Input.GetAxis("Horizontal") < 0)
{
charecterScale.x = -10;
}
if (Input.GetAxis("Horizontal") > 0)
{
charecterScale.x = 10;
}
transform.localScale = charecterScale;
}
}
set the scale down to -1, 1
I have watched 7 tutorials and this is the only one that worked. Thank you for helping me make my first game on unity. :D
This was my first time ever coding player movement, Thank you
You should watch the entire video to understand everything but here is the c# movement script (not the jump one)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Character2DController : MonoBehaviour
{
public float MovementSpeed = 1;
private void Start()
{
}
private void Update()
{
var movement = Input.GetAxis("Horizontal");
transform.position += new Vector3(movement, 0, 0) * Time.deltaTime * MovementSpeed;
}
}
Edit, you need to change the public class to whatever your script name is
im going to just steal- i mean, *borrow* this code (communism music intensifies)
@@galaxytsd Come comrade, we must over take the forums. FOR THE MOTHERLAND!
@@always_failing_at_speed_ru7209 YES IDK WHATS GOING ON!
THX GOD BLESS YOU
also can you make it contain the jumping thing?
This is by far the best Unity 2d tutorial i have came across so far, atfirst i didnt like typing the code cause im lazy but this was very easy, keep up the great work!
Note: if you want to make a level using Tilemaps I don't recommend using that code(For moving right and left) because it will really glitchy so you can use:
void Start()
{
Rb = GetComponent();
}
void Update()
{
float horiz = Input.GetAxisRaw("Horizontal");
Rb.velocity = new Vector2(Speed * horiz, Rb.velocity.y);
}
so it will not so glitchy.
My Rb doesn't wori
@@warredewilde You need to add Rigidbody2D to your character
THANK YOU KING YOU SAVED ME FROM FAILING MY GAME DESIGN CLASS
I've been trying to get this to work for like 5 hours now, this video is the only one that worked.
Video: no errors and 5min
Me made the same: 3 errors and 1hour
Me understanding: ∞ errors and ∞hours
But thank you I made it!
but how
man that's what i'm doing
The amount of frustration and satisfaction I'm feeling right now bro.
Simple to understand.
God bless.
i was looking for a tutorial on how to make the player jump once for about a month! and you did it in 5 minutes, Thanks so much!!!
same for me tho :D I always did it with addforce up lol
his drop menus in the script wont work for me i type in input and nothing shows up same for most of the colored text + =
can someone help in in jumping??
Thanky you sooo much i have been looking for tutorials for 2 weeks and when I found you I was soo happy because it worked and nothing ever worked for me and again thank you soooo much hope you have a good day!
You made the player movement so easy. You are a genius sir
Glad it helped
This is an outstanding video. I would ***instantly*** buy any course that got straight to the point like this.
Figured out the compiler issue. and you should tell people be aware that the "screw driver" icon to the left of the code is there for a reason. it kinda auto corrects coding for you. i was following videos trying to mirror those codes and for some reason the capitalization of certain text was an issue majorly. SO for those seeing confusing compiler issues MAKE SURE you use that screw driver because it will generate the proper text below what you tried code when it comes to capitalization and expression.
how
BEST BY FAR AWARD***
Brand new to all this and have been search non-stop for guidance having to do with movement that didn't rely on premade scripts. Although not every aspect of the code was explained it became more clear after the results manifested. Anyways great job!
Literally incredible and straight to the point. I can not be more thankful.
The system is pretty simple and there is no ground detection but it is pretty beginner friendly and it does the job for now
Thanks you have just earned yourself a new sub
the controls are so smooth, ive watched like ever 2D movement tutorial and this is the best by far
bro this is better than some of the most top notch tutorials out there. straight to the point no extra bs. love it
Hey I don’t agree with your jump system, in the same line you’re checking for a “Jump” input you’re also checking if the y component of our velocity is less than 0.001 (I guess you made this value small enough to kind of simulate when the player is standing) but there are actually 2 situations where our up velocity is close to 0:
-when we are standing still on a surface
-at the pick of our jump (when we’re about to fall back down)
This means that we can still jump infinitely if we press “Jump” just at the right time.
Please correct me if I’m wrong! Other than that I think the video is very good :)
You are 100% correct in your observation. This system was chosen deliberately because it is as simple as it gets. There various other ways of detecting when a character is grounded, but all of them are more complex than an absolute-beginner video requires. The same counts for almost all components :)
@@DistortedPixelStudios I am getting error unexpected ';' in script. Can you help me solve that error??
Edit:Fixed the error but, the jump movement itself is not there in playmode
jump buffering is actually pretty useful, so good for me!
@@DistortedPixelStudios bro i need help when i put camera in my character , character is not turning 180 scale "camera" is turning 180 scale when i eject camera on my character its working but this is the problem if i eject the camera my character is not going with camera and after a while my character disappears from view
You are honestly the best!!! You almost put Brackeys to shame XD
What do you mean almost :)
@@DistortedPixelStudios damn
Thanks For Making This, I Found It Really Clear And Was Easy To Do!
Thank you so much every video i watch allways has a problem and finally it worked yesss
Thank you so much! I am starting to learn how to make games and this was the first obstacle; movement and jumping.
I looked all over the internet to find the right tutorial. So when I found this one, I didn’t think it would be that good, but it did what I wanted it to do.
So thank you!
How is your gamedev doing?
Thank you for cutting through all the junk and getting straight to it. I am brand new to C# and just needed someone to tell me how to get from point A to point B.
This is the best tutorial i've seen so far like no joke
I kid you not, I did this in four minutes compared to the twelve where I was left wondering why my character didn't jump from the other tutorials. Thanks!
using UnityEngine;
public class td: MonoBehaviour
{
public float Movementspeed = 1;
private void Start()
{
}
private void Update()
{
}
var movement = Input.GetAxis("Horizontal");
Transform.Position += new Vektor3(movement, 0, 0) * Time.deltatime* Movementspeed;
}
}
Thaaaaanks 😂
@@ritokun7157 😂 ok
thx
does it have jump in it tho?
Thank you for getting straight quick into the point and not making an hour long video talking about unecessary things, now I actually know how to make movement, thanks!
5 public float MovementSpeed = 1;
6 private void Start()
7 l(
8 l)
10 private void Update()
11 l(
12 var movement = Input.GetAxis("Horizontal");
13 transform.position += new Vector3(movement, 0, 0) * Time . deltaTime = MovementSpeed;
14 l)
15 l(
it’s giving me a compiler error
transform.position += new Vector3(movement, 0, 0) * Time.deltaTime * MovementSpeed;
@@calebweigt2877 yeah no shit sherlock
@@SLRNT thankyou!!
i really got stuck because i couldn't control the character and i didn't have any errors. then i found out that i didn't put the script on my character. it works really well so thank you :)
This is amazing 5 min instead of sooooo long
i thought it was too good to be true
Thanks i didnt expect to actually learn this many things i 5 minutes!!!
so i was wandering why it wasnt working and then i realized i didnt drag the script to the player
That’s a mistake everyone makes lol
thatll do it
@@isaacjames5870 wow you are fast lol
@@noagero7351 what
@@noagero7351 wdym
This helped me so much! I've tried so many tutorials and this is the only one that worked, I also felt I learned a lot from it that I can use in future, thank you!
Any ideas why my character is looking the wrong way, when I followed the script perfectly? The look rotation script thing seems backwards
you should check the scale. I have the same problem ;(
in case anyone else needs it, I modified the statement for transform.rotation instead of movement > 0 is movement < 0
if(!Mathf.Approximately(0,_move)){
transform.rotation = _move < 0 ? Quaternion.Euler(0,180,0) : Quaternion.identity;
}
for me _move is: var _move = Input.GetAxis("Horizontal");
and I copied the comment above by Nislaav that said Unity changed API and followed the tutorial, works like a charm on 2020.3.4f1 :)
Why do I have to use += instead of = for when making the movement? I have tested what happens when u use = and something is defenetly wrong I just dont know why.
I also wondered why we use Vector3 instead of Vector2 for the movement.
`v += 1` is a shorthand for `v = v + 1` but it does the exact same thing
Wow, this was so fast and helpful. Thank you! super underrated!!
My man explained everything in five minutes, everything is working perfectly :D:D
This is the first time I watched a coding tutorial and it actually worked. Thanks for the help.
Ngl this is more efficient than the others, because he only used one script and it can help me by tomorrow, I'll be trying this method
Hello, I've tried inputting the same, but I end up with the error "Assets/Character2DController.cs(11,9): error CS0019: Operator '*=' cannot be applied to operands of type 'Vector3' and 'Vector3'". How can I fix this?
that's +=
@@prakashindustries5941 Yes, it is += not *=
My unity told me that "+=" would not work, it had to be "="
@@jackburt4946 There is not . that why it dose not work
@@onlineteacher2878 ok thank you, I added the plus sign back and it worked
It's clear, and it go where it need to without taking 350 other ways and using complexe language to seem intelligent, I'll recommend it
This really sucks, watching videos that have 30 minutes long then nothing works, and when you watch a 5 minutes video everything works flawlessly :/
I thought you were talking about the video at first glance! XD
the simplest and cleanest tutorial i've ever seen
Why do you make the void Start() and void Update() private? Is that something we should do everytime?
It's just his style of coding. If it works without it and you are learning, stay without it.
With or without it, a void is always private except if you write public behind it, then idk what to expect
@@aminmkyt4191 thx
Mann ich liebe dich ich habe 3 Stunden versucht das zu schaffen und jetzt in 5 Minuten geschafft Danke dir Ehrenmann
Great job, keep it up! And thanks!
This video was the only one that worked for me!!
thanks!
Except for the jumping. :-(
sorry by my english.
Join our discord (link in the description) and we'll help you out with the jumping
My character doesn't move left or right
Hey guys, if there is an error coming that says something about 'jumpforce', change the jumpforce into a number like this = ( 0, 5 ), ıt worked for me. Thank you for this video also
Thank You
how do i let this work i did the same thing and there was 4 errors
@@outbreaker2396 Here You Go
using UnityEngine;
public class Move : MonoBehaviour
{
public float MovementSpeed = 1;
public float JumpForce= 1;
private Rigidbody2D _rigidbody;
private void Start()
{
_rigidbody = GetComponent();
}
private void Update()
{
var movement = Input.GetAxis("Horizontal");
transform.position += new Vector3(movement, 0, 0) * Time.deltaTime * MovementSpeed;
if (Input.GetButtonDown("Jump") && Mathf.Abs(_rigidbody.velocity.y) < 0.001f)
{
_rigidbody.AddForce(new Vector2(0, JumpForce), ForceMode2D.Impulse);
}
}
}
@@gamerbeast7859 i will try it and thx
@@outbreaker2396 I Hope It Will Work
@@gamerbeast7859 the character in my game is a pill and when I put the code in to the player(pill) it says:
the script pill movement dose not contain a class derived from unity engne.monobehaviour
For everyone that is stuck at a wall for etc do this:
2D: If you are on 2D and uses Collider2D as collider then go into "Create > 2D > Physics material 2D" and set the Friction & Bounciness to 0 and on your Player colliders set the material to the physics material you just created.
3D: If you are on 3D and uses Collider as collider then go into "Create > Physics material" and set the Static & Dynamic to 0 (Or keep Dynamic to what it is idk) And on the colliders set the material to the physics material you just created. (If its not working try not changing/do change on the Dynamic setting, Or try Friction Combine to Multiply)
I work more with 3D then 2D so idk anything about the 3D part :D
My code just doesnt seem to work ):
Im not sure if i have a right version of vscode or something the code just doesnt work,i was wathcing brackeys tutorial and it also didnt work.
@Jay Futon unity says that compiled errors have to be fixed before playing,and i've typed the code over a million times
@@nicolasdacosta2963 did you manage to fix it? I'm getting the same
I'm having the same problem.
Did you manage to fix the issue?
OMG DUDE THANK U SO MUCH I HAVE BEEN LOOKING FOR THIS A FEW HOURS
i finished this whole video while my unity was loading lol
same lol
Same
Finally... after so many weeks of trying... I finally got unity to actually do something!
Thank you so much! It was a short but helpful tutorial.
Though there are a few problems, but I think they might be because of a new version.
I was having trouble jumping and I changed two things:
1. I changed the if function to "W" instead of "Jump"
example: (Input.GetKey(KeyCode.W)
2. I added something to help with the velocity continuing after falling
example:
void OnCollisionEnter2D(Collision2D collision)
{
_rigidbody2D.velocity = new Vector3 (0, 0, 0);
}
thanks this solved my problem of not being able to jump
@@monkeypilot Glad I could help!
tbh you saved my motivation i tried the tutorial a few month ago and gave up and now i have the start of a plat former!
@@monkeypilot Cool! I hope it goes well! If you need more tutorials, I whole-heartedly suggest the Brackeys YT channel. They make super helpful and easy to follow videos!
@@Chexmix6 im already subed to him
This teaching style was so simple, and very effective. I am beggining to get the basics of unity and this has really fuelled ne
Hi there!
This is a great and simple video, and it is very easy to understand!
Thank you very much for making this!
If I can make a request: Have you thought about making a video about 2D movement using the new preview input system? It seems really cool, but I can't seem to get a grasp of it...
Thank you for the kind words,
We've had our eye on the New Input System for a while, but we have a policy against writing tutorial content for packages still in preview (has not been officially been released).
We have a couple devs who have experience working with it though, join our discord and I'm certain they will be more than willing to assist!
Here's an Invite link : discord.gg/EVJ2wpt
@@DistortedPixelStudios Thanks!
It makes sense not make tutorials about preview packages 😅
But thanks for link to the discord! I'm soon starting a new project, and it looks like the perfect place to ask questions 😄
@@DistortedPixelStudios hey i need help it says that i cant play it till i fix all the errors but visual studios says i have no errors please get back to me, thanks
Thank you very much, how can I change the key from space to up key??
Don't forget to checkout our community tab!
ruclips.net/user/DistortedPixelStudioscommunity
Here you can let us know what you want to see next!
Ok
Can you help me? after the jumoing script is full with errors :(
Thank you so much for making this video! Its so good and very to the point and concise, from now on in my 2D games I am using this character controller!
why do i have errors i checked the code 5 times and moreee
I was looking everywhere, and this tutorial is the only one that's worked. Thank you so much, this really helped
This short tutorial has helped me to move my character .... thank you
Full code in the video:
using UnityEngine;
public class Character2DController : MonoBehaviour
{
public float _speed = 5;
public float JumpForce = 1;
private Rigidbody2D _rigidbody;
private void Start()
{
_rigidbody = GetComponent();
}
private void Update()
{
var movement = Input.GetAxis("Horizontal");
transform.position += new Vector3(movement, 0, 0) * time.deltatime * MovementSpeed;
if (Input.GetButtonDown("Jump") && Mathf.Abs(_rigidbody.velocity.y) < 0,001f)
{
_rigidbody.AddForce(new Vector3(0, JumpForce), ForceMode2D.Impulse);
}
}
}
thx
This video should have millions of views
Great tutorial ! Thank you! I have a question - when try to add the bonus code that adds the transform rotation the character gets very 'thin' when I turn him around - what am I missing?
Got it! After checking the docs for Quaternion.Euler (my intellisense is broken) - I could see that it was taking degrees as input and that I had entered 100 instead of 180 ! Hence my "thin" sprite!
@@dermotbyrnemusic haha i did the same i didnt notice it was 180 thanks
Thank you so much! The other tutorials didn't work for me, you are a lifesaver
why is it that every tutorial i watch they never work!
@Arvid Renestam Thanks!
You were right, ever since i commented ive learned quite a bit!
what do in look rotation script( 4:37 ) if my character is facing the wrong way so he walks backwards...?
the script doesn't work
Perfect. straight to the point, understandable, and the only one working for me. Thank you so much dude
2:08 I know that could be stupid question to some of us but started learning coding in Visual Studio Code, and wan't to ask why when I type transform.p I don't get any help from program like u can see in that time
Use Visual Studio (Community Edition is free) - Not Visual Studio Code for C# its much much better, especially for beginners
@@RiaanWalters thank you.
@@RiaanWalters I'm still not getting thoes helps + I do not have thoes colors as you can see on video, everything look's white and get's me confuse a little bit.
2:14 there's an error on movement and I can't get it to go away. It says "The name "movement" does not exist in the current context"
I have the same problem
you can use "public Rigidbody2D = _rigidbody;" and in unity editor drag and drop rigidbody to script
dude , thanks so much for this video
the code is excellent: it's easy to understand, very begginer friendly, and works PERFECT'
you sir, earned a new sub!
Ive been trying to move my character for a while and your video was the only one that works! Thanks
Incredible , i'm from spain and i'm not very good at english but you explain so good , thanks for the tutorial :)
me the entire time: i have no idea what he saying but its making my guy move! Thx man!
takeing me a lot of time i'm new in the deveip game.
i found your tutorial and this was great.. your code its so simple! i don't need ground check or whatever to determine that my player on ground or not! thanks
OMG THANK YOU SO MUCH this is the only Video that works
Thank u so very much! I was searchibg fir this for about 2 hours! I subscribed an liked! THANK U SO VERY MUCH
For me it did not work I even did what you did to the lettwrvand it did not work if you can explain please it would help
Literally the best tutorial on the site
Awesome you're so genius my gameobject(player) is moving now. THANKS!!!!!
Thank you so much for this!!!
For anyone wondering why their Visual Studio isn't adding autocompleting the Unity "words" it is because Visual Studio 19 doesn't come with Unity autocomplete, you have to select it. Instead go to tools ---> get tools and features ---> scroll to Game Dev with Unity ---> Modify. THEN in Unity go to edit ---> perferences ---> external tools ---> script editor ---> Visual Studio 19 :)
also here is the function
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ADD YOUR FILE NAME HERE: MonoBehaviour
{
public float MovementSpeed = 1;
public float JumpForce = 1;
private Rigidbody2D _rigidbody;
private void Start()
{
_rigidbody = GetComponent();
}
private void Update()
{
var movement = Input.GetAxis("Horizontal");
transform.position += new Vector3(movement, 0, 0) * Time.deltaTime * MovementSpeed;
if (Input.GetButtonDown("Jump") && Mathf.Abs(_rigidbody.velocity.y) < 0.001f)
{
_rigidbody.AddForce(new Vector2(0, JumpForce), ForceMode2D.Impulse);
}
}
}
TY for this comment It Fixed my issue with the player flying
Simply and great!!
This is a great down-to-earth, essential without any wasting time kind of tutorial. Thank you