2D Character Movement in Unity / 2023

Поделиться
HTML-код
  • Опубликовано: 18 дек 2024

Комментарии •

  • @justapersonontheinternet
    @justapersonontheinternet 4 года назад +92

    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
      @AviyaleTales 2 года назад

      But hes not going into detail assuming you have it all figured out

    • @justapersonontheinternet
      @justapersonontheinternet 2 года назад +2

      @@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

    • @colinhenry3021
      @colinhenry3021 2 года назад

      @@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?

    • @justapersonontheinternet
      @justapersonontheinternet 2 года назад

      @@colinhenry3021 I have definetly improved. Still have to look up essentially everything but atleast now i understand why things work the way they do.

  • @sydneywright8824
    @sydneywright8824 3 года назад +17

    I was struggling with this watching other tutorials. This tutorial was perfectly summed up, clean, and well executed. Thank you so much for this!!!

  • @nislaav6712
    @nislaav6712 3 года назад +169

    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 :)

    • @aiduck8307
      @aiduck8307 3 года назад +3

      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

    • @jutn2
      @jutn2 3 года назад +3

      ty it hepled me!

    • @d3vl0g-unitydevelopment60
      @d3vl0g-unitydevelopment60 3 года назад

      i use 2019.4. which version is this for?

    • @iYuvie
      @iYuvie 3 года назад

      thanks dude
      it work

    • @gu7326
      @gu7326 3 года назад

      thanks man, has saved me a lot of work!!

  • @havendewart
    @havendewart 4 года назад +297

    This video is so under-rated! you simple teaching style has helped me so much. Thank you!

    • @tornanblade665
      @tornanblade665 4 года назад +1

      INNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNIT!

    • @miqdadisbadatgaming2253
      @miqdadisbadatgaming2253 4 года назад +1

      really helped even big brack couldn't help lol

    • @red2go56
      @red2go56 3 года назад +1

      @@miqdadisbadatgaming2253 true i am coding my first game and this video helps me Thanks

    • @AmmarYasser_13
      @AmmarYasser_13 3 года назад

      The whole channel is

    • @MagneticalVR
      @MagneticalVR 3 года назад

      @@miqdadisbadatgaming2253 he used a third party animation controller so that’s why i didn’t follow it

  • @gloopsee3801
    @gloopsee3801 3 года назад +19

    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);
    }
    }
    }

    • @Axegarden
      @Axegarden 2 года назад +1

      hippity hoppity your code is now my property

    • @gloopsee3801
      @gloopsee3801 2 года назад

      @@Axegarden hahah nice one. Is it working?

    • @Axegarden
      @Axegarden 2 года назад

      @@gloopsee3801 for some reason no but i will figure it out tomorrow

    • @chinest3386
      @chinest3386 2 года назад

      @@gloopsee3801 btw I think there is a extra 2 lines of code at the end of the video he doesn’t show

    • @Zisser2000
      @Zisser2000 2 года назад

      @@gloopsee3801 works for me! Thanks!

  • @Sebhowell
    @Sebhowell 3 года назад +6

    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

  • @theshaylife6680
    @theshaylife6680 4 года назад +42

    This is like the only one that’s worked solidly. Thank you!

  • @Moss1403
    @Moss1403 3 года назад +1

    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;
    }
    }

    • @afiyindev
      @afiyindev 3 года назад +1

      All the codes I tried didnt work both from the video and comments.
      But yours did. Bless g

    • @Moss1403
      @Moss1403 2 года назад +1

      @@afiyindev you're welcome :,)

  • @darijus4094
    @darijus4094 3 года назад +9

    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;
    }
    }

  • @bokobro
    @bokobro 2 года назад +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

  • @hollowthing3259
    @hollowthing3259 3 года назад +9

    This was my first time ever coding player movement, Thank you

  • @HvvocYT
    @HvvocYT 3 года назад +21

    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

    • @galaxytsd
      @galaxytsd 3 года назад +2

      im going to just steal- i mean, *borrow* this code (communism music intensifies)

    • @always_failing_at_speed_ru7209
      @always_failing_at_speed_ru7209 3 года назад

      @@galaxytsd Come comrade, we must over take the forums. FOR THE MOTHERLAND!

    • @galaxytsd
      @galaxytsd 3 года назад +1

      @@always_failing_at_speed_ru7209 YES IDK WHATS GOING ON!

    • @O_O-zf7xz
      @O_O-zf7xz 2 года назад

      THX GOD BLESS YOU

    • @O_O-zf7xz
      @O_O-zf7xz 2 года назад

      also can you make it contain the jumping thing?

  • @micklehater22
    @micklehater22 4 года назад +22

    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!

  • @shaladddin5687
    @shaladddin5687 4 года назад +5

    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.

    • @warredewilde
      @warredewilde 3 года назад +1

      My Rb doesn't wori

    • @mkq4044
      @mkq4044 3 года назад

      @@warredewilde You need to add Rigidbody2D to your character

  • @bmercurybelfc
    @bmercurybelfc 4 года назад +16

    THANK YOU KING YOU SAVED ME FROM FAILING MY GAME DESIGN CLASS

  • @shimpputin466
    @shimpputin466 Год назад

    I've been trying to get this to work for like 5 hours now, this video is the only one that worked.

  • @anonymanonym3342
    @anonymanonym3342 3 года назад +51

    Video: no errors and 5min
    Me made the same: 3 errors and 1hour
    Me understanding: ∞ errors and ∞hours
    But thank you I made it!

    • @wolfrikx
      @wolfrikx 3 года назад +1

      but how

    • @머랭-b2g
      @머랭-b2g 3 года назад

      man that's what i'm doing

  • @Sane_Mania
    @Sane_Mania 2 года назад

    The amount of frustration and satisfaction I'm feeling right now bro.
    Simple to understand.
    God bless.

  • @gamelsrael
    @gamelsrael 4 года назад +25

    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!!!

    • @ilija_sigalov
      @ilija_sigalov 4 года назад +1

      same for me tho :D I always did it with addforce up lol

    • @-xtrayed-5755
      @-xtrayed-5755 4 года назад

      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 + =

    • @ZeonplayzYt
      @ZeonplayzYt 4 года назад

      can someone help in in jumping??

  • @ZeroFiks
    @ZeroFiks 2 года назад

    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!

  • @usamaiftikhar934
    @usamaiftikhar934 4 года назад +3

    You made the player movement so easy. You are a genius sir

  • @pianoatthirty
    @pianoatthirty 2 года назад +1

    This is an outstanding video. I would ***instantly*** buy any course that got straight to the point like this.

  • @xDTHECHEMISTx
    @xDTHECHEMISTx 3 года назад +7

    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.

  • @gui8571
    @gui8571 3 года назад

    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!

  • @funiman4404
    @funiman4404 4 года назад +4

    Literally incredible and straight to the point. I can not be more thankful.

  • @user-is5fh3wy4p
    @user-is5fh3wy4p 10 месяцев назад

    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

  • @FranSkok04
    @FranSkok04 3 года назад +10

    the controls are so smooth, ive watched like ever 2D movement tutorial and this is the best by far

  • @novarl4115
    @novarl4115 2 года назад

    bro this is better than some of the most top notch tutorials out there. straight to the point no extra bs. love it

  • @supernectar5022
    @supernectar5022 4 года назад +6

    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 :)

    • @DistortedPixelStudios
      @DistortedPixelStudios  4 года назад +6

      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 :)

    • @ONEEYEDKING01
      @ONEEYEDKING01 4 года назад +1

      @@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

    • @sparklingwater6638
      @sparklingwater6638 3 года назад

      jump buffering is actually pretty useful, so good for me!

    • @xentergamescompanies4052
      @xentergamescompanies4052 2 года назад

      @@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

  • @aricksmith5736
    @aricksmith5736 4 года назад +2

    You are honestly the best!!! You almost put Brackeys to shame XD

  • @stefantuba
    @stefantuba 4 года назад +6

    Thanks For Making This, I Found It Really Clear And Was Easy To Do!

  • @thegoldendart3219
    @thegoldendart3219 3 года назад

    Thank you so much every video i watch allways has a problem and finally it worked yesss

  • @megaomega9907
    @megaomega9907 4 года назад +10

    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!

    • @Gamer-tj3ew
      @Gamer-tj3ew 3 года назад

      How is your gamedev doing?

  • @foolofatook4925
    @foolofatook4925 2 года назад

    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.

  • @RandoDudle
    @RandoDudle 4 года назад +6

    This is the best tutorial i've seen so far like no joke

  • @xmas7o748
    @xmas7o748 3 года назад +1

    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!

  • @Gambitlagyna
    @Gambitlagyna 4 года назад +3

    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;
    }
    }

  • @erglwrgl
    @erglwrgl 3 года назад

    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!

  • @support_gaza
    @support_gaza 3 года назад +6

    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(

    • @calebweigt2877
      @calebweigt2877 3 года назад +2

      it’s giving me a compiler error

    • @SLRNT
      @SLRNT 2 года назад +1

      transform.position += new Vector3(movement, 0, 0) * Time.deltaTime * MovementSpeed;

    • @grindx1292
      @grindx1292 2 года назад

      @@calebweigt2877 yeah no shit sherlock

    • @COSMICAMISSION
      @COSMICAMISSION 2 года назад +1

      @@SLRNT thankyou!!

  • @spo0ds152
    @spo0ds152 4 года назад

    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 :)

  • @mrfizzvfx7051
    @mrfizzvfx7051 4 года назад +3

    This is amazing 5 min instead of sooooo long

  • @tokogodu7761
    @tokogodu7761 3 года назад

    i thought it was too good to be true
    Thanks i didnt expect to actually learn this many things i 5 minutes!!!

  • @noagero7351
    @noagero7351 4 года назад +15

    so i was wandering why it wasnt working and then i realized i didnt drag the script to the player

  • @Piparoodle
    @Piparoodle Год назад

    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!

  • @XD_Wario
    @XD_Wario 3 года назад +4

    Any ideas why my character is looking the wrong way, when I followed the script perfectly? The look rotation script thing seems backwards

    • @Big-f2p
      @Big-f2p 3 года назад +1

      you should check the scale. I have the same problem ;(

    • @chrysy99
      @chrysy99 3 года назад

      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 :)

  • @shesapirate1306
    @shesapirate1306 2 года назад +2

    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.

    • @RiaanWalters
      @RiaanWalters 2 года назад

      `v += 1` is a shorthand for `v = v + 1` but it does the exact same thing

  • @jaiergordon1
    @jaiergordon1 4 года назад +3

    Wow, this was so fast and helpful. Thank you! super underrated!!

  • @abduez7248
    @abduez7248 3 года назад

    My man explained everything in five minutes, everything is working perfectly :D:D

  • @kerwinramage4162
    @kerwinramage4162 4 года назад +3

    This is the first time I watched a coding tutorial and it actually worked. Thanks for the help.

  • @ijazzqant7321
    @ijazzqant7321 4 года назад

    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

  • @koha_2110
    @koha_2110 4 года назад +16

    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?

    • @prakashindustries5941
      @prakashindustries5941 4 года назад +5

      that's +=

    • @ZaneWipfli
      @ZaneWipfli 4 года назад +1

      @@prakashindustries5941 Yes, it is += not *=

    • @jackburt4946
      @jackburt4946 4 года назад +1

      My unity told me that "+=" would not work, it had to be "="

    • @onlineteacher2878
      @onlineteacher2878 4 года назад +1

      @@jackburt4946 There is not . that why it dose not work

    • @jackburt4946
      @jackburt4946 4 года назад

      @@onlineteacher2878 ok thank you, I added the plus sign back and it worked

  •  3 года назад

    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

  • @soflass1293
    @soflass1293 3 года назад +28

    This really sucks, watching videos that have 30 minutes long then nothing works, and when you watch a 5 minutes video everything works flawlessly :/

    • @Chexmix6
      @Chexmix6 3 года назад +4

      I thought you were talking about the video at first glance! XD

  • @zakidz6716
    @zakidz6716 4 года назад +1

    the simplest and cleanest tutorial i've ever seen

  • @anton9814
    @anton9814 4 года назад +3

    Why do you make the void Start() and void Update() private? Is that something we should do everytime?

    • @ihavecreatism9776
      @ihavecreatism9776 4 года назад

      It's just his style of coding. If it works without it and you are learning, stay without it.

    • @aminmkyt4191
      @aminmkyt4191 4 года назад

      With or without it, a void is always private except if you write public behind it, then idk what to expect

    • @Chill_Wolf
      @Chill_Wolf 3 года назад

      @@aminmkyt4191 thx

  • @vincent5399
    @vincent5399 4 года назад +1

    Mann ich liebe dich ich habe 3 Stunden versucht das zu schaffen und jetzt in 5 Minuten geschafft Danke dir Ehrenmann

  • @ektelion
    @ektelion 4 года назад +4

    Great job, keep it up! And thanks!

  • @musketslinger
    @musketslinger 4 года назад +2

    This video was the only one that worked for me!!
    thanks!
    Except for the jumping. :-(
    sorry by my english.

    • @DistortedPixelStudios
      @DistortedPixelStudios  4 года назад

      Join our discord (link in the description) and we'll help you out with the jumping

  • @blazer6972
    @blazer6972 2 года назад +4

    My character doesn't move left or right

  • @lokotot834
    @lokotot834 4 года назад +1

    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
    @gamerbeast7859 3 года назад +3

    Thank You

    • @outbreaker2396
      @outbreaker2396 3 года назад +2

      how do i let this work i did the same thing and there was 4 errors

    • @gamerbeast7859
      @gamerbeast7859 3 года назад +2

      @@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);

      }
      }

      }

    • @outbreaker2396
      @outbreaker2396 3 года назад +1

      @@gamerbeast7859 i will try it and thx

    • @gamerbeast7859
      @gamerbeast7859 3 года назад +2

      @@outbreaker2396 I Hope It Will Work

    • @outbreaker2396
      @outbreaker2396 3 года назад +2

      @@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

  • @marexexe7308
    @marexexe7308 3 года назад +1

    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

  • @nicolasdacosta2963
    @nicolasdacosta2963 4 года назад +3

    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.

    • @nicolasdacosta2963
      @nicolasdacosta2963 4 года назад

      @Jay Futon unity says that compiled errors have to be fixed before playing,and i've typed the code over a million times

    • @vandacroft1379
      @vandacroft1379 4 года назад

      @@nicolasdacosta2963 did you manage to fix it? I'm getting the same

    • @himekannachan
      @himekannachan 4 года назад

      I'm having the same problem.
      Did you manage to fix the issue?

  • @orivat3845
    @orivat3845 3 года назад +1

    OMG DUDE THANK U SO MUCH I HAVE BEEN LOOKING FOR THIS A FEW HOURS

  • @princetima2666
    @princetima2666 4 года назад +9

    i finished this whole video while my unity was loading lol

  • @kaidoust4145
    @kaidoust4145 3 года назад

    Finally... after so many weeks of trying... I finally got unity to actually do something!

  • @Chexmix6
    @Chexmix6 3 года назад +4

    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
      @monkeypilot 2 года назад

      thanks this solved my problem of not being able to jump

    • @Chexmix6
      @Chexmix6 2 года назад +1

      @@monkeypilot Glad I could help!

    • @monkeypilot
      @monkeypilot 2 года назад

      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!

    • @Chexmix6
      @Chexmix6 2 года назад

      ​@@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!

    • @monkeypilot
      @monkeypilot 2 года назад

      @@Chexmix6 im already subed to him

  • @po1l
    @po1l 3 года назад +1

    This teaching style was so simple, and very effective. I am beggining to get the basics of unity and this has really fuelled ne

  • @kirckhoffFoght
    @kirckhoffFoght 4 года назад +3

    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...

    • @DistortedPixelStudios
      @DistortedPixelStudios  4 года назад +1

      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

    • @kirckhoffFoght
      @kirckhoffFoght 4 года назад

      @@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 😄

    • @Kmp1834
      @Kmp1834 4 года назад

      @@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??

  • @DistortedPixelStudios
    @DistortedPixelStudios  3 года назад +3

    Don't forget to checkout our community tab!
    ruclips.net/user/DistortedPixelStudioscommunity
    Here you can let us know what you want to see next!

  • @colincostello1630
    @colincostello1630 4 года назад +2

    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!

  • @wolfrikx
    @wolfrikx 3 года назад +3

    why do i have errors i checked the code 5 times and moreee

  • @melinacastro3730
    @melinacastro3730 3 года назад

    I was looking everywhere, and this tutorial is the only one that's worked. Thank you so much, this really helped

  • @rahatshah2452
    @rahatshah2452 2 года назад

    This short tutorial has helped me to move my character .... thank you

  • @mokkro8257
    @mokkro8257 2 года назад +5

    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);
    }
    }
    }

  • @thetiker9719
    @thetiker9719 2 года назад

    This video should have millions of views

  • @dermotbyrnemusic
    @dermotbyrnemusic 4 года назад +3

    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?

    • @dermotbyrnemusic
      @dermotbyrnemusic 4 года назад +4

      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!

    • @ruizon6899
      @ruizon6899 3 года назад +1

      @@dermotbyrnemusic haha i did the same i didnt notice it was 180 thanks

  • @candylide
    @candylide 2 года назад

    Thank you so much! The other tutorials didn't work for me, you are a lifesaver

  • @Charlie-ei4wh
    @Charlie-ei4wh 4 года назад +3

    why is it that every tutorial i watch they never work!

    • @Charlie-ei4wh
      @Charlie-ei4wh 4 года назад

      @Arvid Renestam Thanks!
      You were right, ever since i commented ive learned quite a bit!

  • @gandalfgamer256
    @gandalfgamer256 3 года назад

    what do in look rotation script( 4:37 ) if my character is facing the wrong way so he walks backwards...?

  • @MyysticYT
    @MyysticYT 3 года назад +3

    the script doesn't work

  • @fachri17
    @fachri17 4 года назад +1

    Perfect. straight to the point, understandable, and the only one working for me. Thank you so much dude

  • @ciastekl
    @ciastekl 2 года назад

    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
      @RiaanWalters 2 года назад +1

      Use Visual Studio (Community Edition is free) - Not Visual Studio Code for C# its much much better, especially for beginners

    • @ciastekl
      @ciastekl 2 года назад

      @@RiaanWalters thank you.

    • @ciastekl
      @ciastekl 2 года назад

      @@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.

  • @Purrpluh
    @Purrpluh 3 года назад

    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"

    • @hawkis268
      @hawkis268 3 года назад

      I have the same problem

  • @patatopeeler3005
    @patatopeeler3005 4 года назад +2

    you can use "public Rigidbody2D = _rigidbody;" and in unity editor drag and drop rigidbody to script

  • @a1exism
    @a1exism 3 года назад +1

    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!

  • @leafo4
    @leafo4 4 года назад

    Ive been trying to move my character for a while and your video was the only one that works! Thanks

  • @juanfron8619
    @juanfron8619 3 года назад

    Incredible , i'm from spain and i'm not very good at english but you explain so good , thanks for the tutorial :)

  • @LiamIsCool2008
    @LiamIsCool2008 3 года назад

    me the entire time: i have no idea what he saying but its making my guy move! Thx man!

  • @josukemcmecool3746
    @josukemcmecool3746 3 года назад

    takeing me a lot of time i'm new in the deveip game.

  • @marvelous812
    @marvelous812 3 года назад

    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

  • @toxitaku
    @toxitaku 4 года назад +1

    OMG THANK YOU SO MUCH this is the only Video that works

  • @captainoberon3086
    @captainoberon3086 3 года назад

    Thank u so very much! I was searchibg fir this for about 2 hours! I subscribed an liked! THANK U SO VERY MUCH

  • @Darkened_music
    @Darkened_music Год назад +2

    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

  • @ponchonoob_2724
    @ponchonoob_2724 3 года назад

    Literally the best tutorial on the site

  • @gozammergoza4504
    @gozammergoza4504 3 года назад

    Awesome you're so genius my gameobject(player) is moving now. THANKS!!!!!

  • @schauerv
    @schauerv 3 года назад

    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);
    }
    }
    }

    • @blurple9806
      @blurple9806 3 года назад

      TY for this comment It Fixed my issue with the player flying

  • @adamgriffin3415
    @adamgriffin3415 2 года назад

    Simply and great!!

  • @Notreal76
    @Notreal76 3 года назад

    This is a great down-to-earth, essential without any wasting time kind of tutorial. Thank you