Unity 2D - RPG Tutorial 2024 - Part 02 Character movement

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

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

  • @coenlangille
    @coenlangille Год назад +155

    for those wondering why their character is stuck under the tile map, when inspecting the character sprite, you must set its order of layer to 1.

  • @marcusferreira6558
    @marcusferreira6558 Год назад +115

    Full code:
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class PlayerController : MonoBehaviour
    {
    public float moveSpeed;
    private bool isMoving;
    private Vector2 input;
    private void Update()
    {
    if (!isMoving)
    {
    input.x = Input.GetAxisRaw("Horizontal");
    input.y = Input.GetAxisRaw("Vertical");
    if (input != Vector2.zero)
    {
    var targetPos = transform.position;
    targetPos.x += input.x;
    targetPos.y += input.y;
    StartCoroutine(Move(targetPos));
    }
    }
    }
    IEnumerator Move(Vector3 targetPos)
    {
    isMoving = true;
    while ((targetPos - transform.position).sqrMagnitude > Mathf.Epsilon)
    {
    transform.position = Vector3.MoveTowards(transform.position, targetPos, moveSpeed * Time.deltaTime);
    yield return null;
    }
    transform.position = targetPos;
    isMoving = false;
    }
    }

  • @gamedevscholar6417
    @gamedevscholar6417 Год назад +31

    Thanks for making these. I've gone through Unity's 3D and general Game Dev Tutorials which have given me such a good foundation and have been seeking tutorials for the 2D side of things & wanted a different style / perspective. I think you present your information well and I really appreciate your inclusion of Assets with the goal of hitting the ground running.
    Please keep creating educational content, your presentation is calm, informative and easy to follow. I think your mindset about teaching to think and not just providing the code, etc. is important and will really help people learn and create.
    Looking forward to finishing your series and whatever you have next

    • @epicgdev
      @epicgdev  Год назад +6

      Thank you very much! It made my day!

    • @stickster44
      @stickster44 Год назад +1

      I had to hard-code the move speed to get my player to move: public float moveSpeed = 2;

  • @leinardesteves3987
    @leinardesteves3987 9 месяцев назад +5

    You are probably the best teacher in youtube when it comes to unity. You explain the purpose first, and then what each function does. Easy to remember, and gets people to understand the lesson. You also break them down into section. Amazing work!

  • @jessejohnson4997
    @jessejohnson4997 Год назад +8

    I loved your explanations on each line of code and it really helped. I started putting comments on them in my own so I refer back and hopefully learn! Thank you for this!

  • @MarkPariss
    @MarkPariss Месяц назад +2

    Amazing Tutorial!!!! If anyone is having the same problem as me with the jittering and the movement problem just make sure to add "isMoving =true;" at the beggining of your IEnumerator function so -->
    IEnumerator Move(Vector3 targetPos)
    {
    isMoving = true;
    while...

  • @echomouser
    @echomouser 8 месяцев назад

    Sick dude! Loved the explanations of the code! The math behind it is a little hard for me to grasp but I hope to understand it someday! :D Keep it up!

  • @lordfukuda9234
    @lordfukuda9234 Год назад +16

    For those who are having trouble with movement even though your code was same as he is check the inspector window and check the "tag" if it's on player and when you input the script on the player component just add 1 on movement bellow the "script name"

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

      How, I don't understand? Can you explain a little more?

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

      Hi I'm not sure I follow, my code is exactly the same, I made the tag "Player" and then set movement to 3 and it still doesn't work.

    • @Aguyfrom225
      @Aguyfrom225 9 месяцев назад

      Im having problems because input is ambiguous reference between unityengine and unityengine.windows
      Cs0104 error goes away if i type Input and not input

    • @angelkaki5707
      @angelkaki5707 6 месяцев назад

      @@jaypalmer0616 He is talking bout the Player Controller (script) you should see the Move Speed and set that to 1

  • @rafirizqullahramadhan6257
    @rafirizqullahramadhan6257 Год назад +1

    This video is really helpful for me, because i am a vocational high school students majoring in game development. Thank you so much for making this kind of video, keep doing it and i already subscribed you

  • @8bitenial313
    @8bitenial313 Год назад +4

    10 years working with Unity and it's the first time I see this approach to player movement outside of a "point and click" situation 😂
    Maybe not the best solution for newbies, but nice and smooth "tiled" movement! 😉

    • @epicgdev
      @epicgdev  Год назад +5

      I'm a noobies sharing what i learn :D I would love feedback thank you!!!

  • @TOMMY_QIU
    @TOMMY_QIU 5 месяцев назад

    Excellent Tutorial!Thanks from China. I can't find a good tutorial in my country's local social media, finally ,I find this. Very useful!

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

    your explanations are really clear and easy to understand, thank you!

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

      You're very welcome!

  • @MiguelPerez-ui2gy
    @MiguelPerez-ui2gy 5 месяцев назад +1

    Hey man great video, you are truly a reference!
    Btw, in case you are interested, I suggest to replace the code:
    targetPos.x += input.x;
    targetPos.y += input.y;
    with this one
    targetPos += (Vector3) input;
    Its a one liner and considers the z coordinate of input as 0, which is exactly what we want.

  • @squarecircle1473
    @squarecircle1473 5 месяцев назад +1

    I think the best way to go about it is to learn c# first. I'd love making a game like this, but I'm currently only doing c#. Managed to make a text-based RPG console app with a leveling system and currently building a console-based library management system lol. I know its simple but I feel proud of it :D I am very much enjoying coding tbh. It's surprisingly creative in that you're actively building stuff, but its also abstract and requires problem-solving which I enjoy. My area of expertise is visual arts, so coding is a really nice supplement to that and game dev is a great way of bringing that together. I'm looking forward to learning more c# and getting more intuitive with it. I''ll come back to these lessons when ready. I think your teaching style is great! :)

    • @alessandro7630
      @alessandro7630 3 месяца назад

      Hi, I have a similiar background since I was studying as an illustrator and now I’m studying coding (I took the cs50 course and some other things). Do you recommend any source for studying c#?

  • @RichardCalder67
    @RichardCalder67 2 года назад +28

    You should be doing movement in FixedUpdate, not Update. Otherwise your movement is going to be dependent on the user's computer power. A very fast computer will make your character move crazy fast. FixedUpdate solves this problem. At this point I would also suggest using the newer Input system, it just makes this stuff a lot easier.

    • @SentinalSlice
      @SentinalSlice Год назад +4

      How would someone go about fixing that. Just switch update with fixed update?

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

      @@SentinalSlice Yup, anything that you don't want tied to the actual frame rate the computer will play at should go in fixed_update.

    • @welcomelittlefellow
      @welcomelittlefellow Год назад +9

      The deltaTime already takes care of that as although a frame update might be called sooner, the deltatime will be less and therefore the movement increment will be the same for any computer speed. if you want to simplify this code, I would get rid of the coroutine ;) `void Update()
      {
      input.x = Input.GetAxisRaw("Horizontal");
      input.y = Input.GetAxisRaw("Vertical");
      var targetPos = transform.position;
      targetPos.x += input.x;
      targetPos.y += input.y;
      transform.position = Vector3.MoveTowards(transform.position, targetPos, moveSpeed * Time.deltaTime);
      } `

    • @BG-chain
      @BG-chain Год назад +3

      ​@@welcomelittlefellow
      (RU) все можно сделать еще проще (но я использую физическое движение), например:
      (EN) everything can be made even simpler (but I use physical movement), for example:
      private const float VSpeed = 250f;
      private const float HSpeed = 200f;
      private Rigidbody2D _physics;
      private void Awake()
      {
      _physics = GetComponent();
      }
      private void FixedUpdate()
      {
      Movement();
      }
      private void Movement()
      {
      _physics.velocity = transform.TransformDirection(new Vector2(GetHorizontal(), GetVertical()));
      }
      private static float GetVertical()
      {
      return Input.GetAxis("Vertical") * VSpeed * Time.fixedDeltaTime;
      }
      private static float GetHorizontal()
      {
      return Input.GetAxis("Horizontal") * HSpeed * Time.fixedDeltaTime;
      }

    • @PootisPenserPow
      @PootisPenserPow Год назад +1

      Morrowind taught me this, don't tie functions to framerate

  • @billal7185
    @billal7185 Год назад +1

    Good series so far! Nice level-flexible delivery

  • @ournny851
    @ournny851 Год назад +3

    This's amazing and I learned so much, thank you

  • @josephbeau-reder813
    @josephbeau-reder813 Год назад +1

    Very good video, I downloead unity 1h ago, this is the best I could look for, ty man

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

    nice, looking forward for next tutorial

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

      More coming soon! Thank you for the support!

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

      hey @regejs, have you been trying to learn Unity?

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

    Hey! Just discovered your videos, Thank you for your work Bro, very cool!

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

      Welcome to the channel! If you would like, join our discord community!

  • @voidkon5581
    @voidkon5581 8 месяцев назад

    mr Epic Dev bro . good shit bro
    . best regards VoidKon.

  • @NoahElkins-pe4lz
    @NoahElkins-pe4lz 9 месяцев назад +3

    Can Somone help me please I coded all the player movment in VS Code and applied to my player but i dont have an option to set the movment speed within inspector. Ive done multiple tutorials and this always happens to me i am unsure of what to do i cannot go any further I would really appreciate any help

    • @LiamDERUSHIE-u9g
      @LiamDERUSHIE-u9g 6 месяцев назад

      This has happened to me and all you got to do is if it says moveSpeed you have to always cap the s in it

  • @Caden_is_cool
    @Caden_is_cool Год назад +5

    Can someone help me? It says vector2 does not contain a definition for GetAxisRaw

    • @Aguyfrom225
      @Aguyfrom225 9 месяцев назад

      I got same problem

    • @spijkie83
      @spijkie83 5 месяцев назад

      I think you might have solved this already, but maybe for someone else with the same problem. Make sure you it's Input.GetAxisRaw, with capital I, Input refers to the input system from Unity, input with lower i refers to the variable you created with public Vector2 input;

    • @buntygamer5250
      @buntygamer5250 2 месяца назад

      Write capital v its

  • @oscar7luffy
    @oscar7luffy Год назад +4

    Yep! My character stays under the floor and the solution given in the comments doesn't work. What worked is to put 1 in "Order in Layer" in the Additional Settings of the character. Also it is so small, I had to put x:4 and y:4 in the Scale option. Why is that? I followed all the video :( I know we sliced the background in 32x32 but idk...

    • @kira890
      @kira890 11 месяцев назад +1

      we sliced the background 16x16, no? And the character 16x32? Anyway, I hope you found a solution! c:

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

    Nice tutos, thank you much.
    In Windows, just Ctrl+Mousewheel to zoom in or out directly in VS (maybe works with cmd on mac).
    M. D.

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

      Thank you so much! I will be checking this out :D

  • @StoicMeditationsAtoZ
    @StoicMeditationsAtoZ 6 месяцев назад

    Love this tutorial , thanks for making it simple

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

    25:31 can anybody tell me why do after I put the script onto the player the "move speed" is not there, somebody pls help

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

      did you set your moveSpeed variable public or private?

    • @kuyashiix
      @kuyashiix 11 месяцев назад

      @@anjubatus I'm having the same issue, mine was set to public. I switched it to private and it still won't let me add anything to "Move Speed" in the component script.
      Edit: I figured out the issue, I forgot some ; when writing the code. As someone who knows nothing about coding, this tutorial goes much too fast and assumes a lot. I really think the code should have just been a copy paste because even after the video is over, writing this code manually taught me nothing thanks to the explanation being vague or 'google this' being the explanation.

  • @cj.shot8616
    @cj.shot8616 8 месяцев назад +2

    Guys i wrote all the codes, but character doesn't move. Can someone help me?

  • @kizuma_
    @kizuma_ 11 месяцев назад +6

    If someone wants a "simpler", more elegant solution, it also stores the facing direction in case someone wants to animate the character accordingly:
    public class PlayerController : MonoBehaviour
    {
    public float moveSpeed = 5f;
    public Vector2 facingDirection { get; private set; }
    private void Update() {
    HandleInputs();
    }
    private void HandleInputs() {
    Vector2 direction = new Vector2(
    Input.GetAxisRaw("Horizontal"),
    Input.GetAxisRaw("Vertical")
    );
    direction = direction.normalized * moveSpeed * Time.deltaTime;
    transform.position += new Vector3(direction.x, direction.y, 0);
    facingDirection = direction.normalized;
    }
    }

    • @R1project0
      @R1project0 11 месяцев назад

      Thanks man, works like a charm!
      how could you restrict movement to horizontal and vertical to avoid diagonal movement?
      I tried adding the same line shown in the tutorial but it doesn't work. I'd really appreciate it!

    • @kizuma_
      @kizuma_ 11 месяцев назад +2

      Yes! you could change your HandleInputs to
      private void HandleInputs() {
      Vector2 direction = new Vector2(
      Input.GetAxisRaw("Horizontal"),
      Input.GetAxisRaw("Vertical")
      );
      if(direction.x != 0 && direction.y != 0) {
      direction.x = 0; // if you want to prioritize up/down movement, otherwise use .y
      }
      direction = direction.normalized * moveSpeed * Time.deltaTime;
      transform.position += new Vector3(direction.x, direction.y, 0);
      facingDirection = direction.normalized;
      }
      this way, if the player walks e.g. right/up, he will only walk up instead.
      @@R1project0

    • @lyneyzi
      @lyneyzi 11 месяцев назад

      Thanks so much for this!

    • @lyneyzi
      @lyneyzi 11 месяцев назад

      How would I animate the character sprites though?

    • @beeplushiee
      @beeplushiee 11 месяцев назад

      @@lyneyzi This is my code and it seems to animate as it should
      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;
      public class PlayerController : MonoBehaviour
      {
      public float moveSpeed;
      public Vector2 facingDirection { get; private set; }
      private Animator animator;
      void Awake()
      {
      animator = GetComponent();
      }
      private void Update()
      {
      HandleInputs();
      }
      private void HandleInputs()
      {
      Vector2 direction = new Vector2(Input.GetAxisRaw("Horizontal"),Input.GetAxisRaw("Vertical"));
      if(direction.x != 0 && direction.y != 0)
      {
      direction.y = 0;
      }
      animator.SetBool("IsMoving", true); // change "IsMoving" to whatever your equivalent is
      direction = direction.normalized * moveSpeed * Time.deltaTime;
      animator.SetFloat("moveX", direction.x); // change "moveX" to whatever your equivalent is
      animator.SetFloat("MoveY", direction.y); // change MoveY" to whatever your equivalent is
      transform.position += new Vector3(direction.x, direction.y, 0);
      facingDirection = direction.normalized;
      }
      }

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

    Hey, quick question just want to make sure I download everything right (New to programming completely) Visual Studio comes with a lot of stuff to ask before installing, totaling to about 11.4GB of downloads. Is that the right path? It's a little long list of tools to write - don't want to clutter your comment box.
    P.S. If you're willing, consider opening a discord for questions, or just to converse. So stoked that you made this tutorial for us and I just want to make sure I follow it properly.
    Thanks,

  • @TheTarnisher
    @TheTarnisher Год назад +1

    These are excellent tutorials

  • @Gameboy316-real
    @Gameboy316-real Год назад +2

    I need help it says isMoving = false; has I invalid token

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

    Hey, great video. I made everything until the 3rd NPC is created and now I try to understand everything. What is I don’t understand is why a Coreroutine is used and why it should be used? Isn’t it a bit overkill for such an easy game? Or is ist really important for further game development as an armature?

  • @Noolemans
    @Noolemans Месяц назад

    Very helpful, thanks man!

  • @Goqts
    @Goqts Год назад +5

    Hey, I love the tutorials! Unfortunately, a little confused -- how am I supposed to actually move my character? -- I understand the code and why you have put each line, but when I run it, my character doesn't move and my assumption is because I haven't correlated any keys actually WITH movement. What keys are supposed to move the character? How am I meant to move it?

    • @dong-wang8257
      @dong-wang8257 Год назад +2

      i had this issue too, look at the bottom left corner of unity, if it says "input axis Horizontal/Vertical not set up" then just go into your code on visual studio, and make sure that the letters H and V are capitalised in your input.x = Input.GetAxisRaw("Horizontal");
      input.y = Input.GetAxisRaw("Vertical");

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

      @Attyelep i am also having the same problem ? did each step correct... do you have any solution?

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

      hopping on the bandwagon here, I can't figure out what is wrong. code is identical, letters capitalized. at a loss

    • @natirsagohuis4062
      @natirsagohuis4062 6 месяцев назад +1

      I had the same issue, until I realized that in the while loop I wrote:
      targetPos = Vector3.MoveTowards(transform.position, targetPos, moveSpeed * Time.deltaTime);
      instead it should be:
      transform.position = Vector3.MoveTowards(transform.position, targetPos, moveSpeed * Time.deltaTime);
      I hope this helps.

    • @mni4975
      @mni4975 2 месяца назад

      @@natirsagohuis4062 Thank you very much! that got me out of a pickle :D

  • @justicedunne6736
    @justicedunne6736 8 месяцев назад +1

    I have a question! I like the addition of not being able to move diagonally, however when I move up and down I can be holding the up arrow key and press the left arrow key to move left for a moment, then release and continue moving up. However if I hold the left arrow key down and try tapping the up or down arrow keys I stay only moving left. How can I fix this so that both directions act the same?

  • @iamqueen1211
    @iamqueen1211 Месяц назад

    How to bring your Character to the front of the BG ?
    1. Look your right side, there's a Sprite Render of the character
    2. To the Additional Settings > Sorting Layer ( which only has Default )
    3. Add 2 Sorting Layer ( or more if you want ) > Layer1 : Background, Layer 2 : Character
    4. You can change the sorting order anytime. Unlike Adobe system, here bottom layer will show on the top. ( I stuck here for 15min 🫠)
    Hope it will solve your problem

  • @omarpokemon9626
    @omarpokemon9626 11 месяцев назад +3

    For people that the player is not moving be careful of writing IEnumerable insted of IEnumerator in the Move function. This happened to me and I was struggling for like an hour or so

    • @meow-pi3xu
      @meow-pi3xu 10 месяцев назад +2

      omg ty for typing this i literally had the same problem 😭

  • @nhuttran9757
    @nhuttran9757 Год назад +1

    really helpful docs, but can you show me how to edit assets with nice borders like yours, when I drag over from the tile palette, the border just isn't pretty and there's a bunch of redundant colors

  • @matthewlavigueur6210
    @matthewlavigueur6210 4 месяца назад

    Had to make an adjustment as my player wasn't moving (even though I had the exact game code). This fixed it for me.
    Added to variables:
    //set Vector 3 in scope
    private Vector3 targetPos;
    and replace your first if statment with this:
    if (input != Vector2.zero)
    {
    // Calculate the target position
    targetPos = transform.position + new Vector3(input.x, input.y, 0) * moveSpeed * Time.deltaTime;
    // Start moving towards the target if not already moving
    if (!isMoving)
    {
    StartCoroutine(Move(targetPos));
    }
    }

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

    could anyone explain to me why input is delayed( character keeps moving for a little while after i press the button )

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

    just getting into game development with unity, had followed a tute for just using java. These videos are quite helpful. I would say, being a programmer I can follow you easy enough, but for people who don't know much, a bit more explanation if possible on the programming side of things would be appreciated - unless of course you were wanting us to go to someone else for a more detailed look of things.

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

    Thats exactly what i needed :) thanx bro

  • @thatdude8022
    @thatdude8022 Год назад +5

    my character moves very slow and delayed

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

    Can you tell me what extension are you using? thank you

  • @zontraxz9910
    @zontraxz9910 Год назад +1

    Hi! been loving your videos so far, but I got a question. How do you make it so VSC shows you what's inside a function like in 22:30?

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

      I need to make a video about that

  • @its_smoggy3502
    @its_smoggy3502 9 месяцев назад +1

    when i drag player sprite it just shows as orange outline, doesnt show in game view

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

    This high quality, I've had coding classes, and I'm looking at things I've never even considered. You're not offering a simple movement script here, you're offer THE movement script. Like this is along the lines of what you should do to make it work professionally.

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

    Help my character is behind the background how do i fix this? Edit: i just added it i didn’t script yet

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

    I'm loving the tutorial so far, but while putting in "targetPos" I get an error. My C# dosen't detect "targetPos" Any reason as to why?

    • @Aguyfrom225
      @Aguyfrom225 9 месяцев назад

      Delete the script and retype the entire thing. Make sure to fully delete old c script file. I had problems but this is a great solution

  • @tonguyenducmanh
    @tonguyenducmanh 9 месяцев назад

    thank u for created this series

  • @CodenTheSynth
    @CodenTheSynth Год назад +5

    for those who get their character behind the tileset, go to 3d mode and move your character to the front a bit...

  • @tomasmartins3820
    @tomasmartins3820 Месяц назад

    Can someone tell me why my character has inverted controls :
    I clik up and it goes down
    I click rigth and it goes left
    Plese help im to dumb to understand this

  • @Zanarkand_0
    @Zanarkand_0 Год назад +1

    Damn. Spent an hour wondering why my character was jittering and it was because I was missing a " } "

  • @nelsonrodriguez9646
    @nelsonrodriguez9646 10 месяцев назад

    When I type Vector2 the text does not turn green, and when I hover the cursor over it, there seems to be locks on the list of vectors. Can someone help with this?

  • @iamneoficial
    @iamneoficial 9 месяцев назад

    Thanks 🎉

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

    Great video, the only thing I wish that was in it was how you got all the autocomplete and other things ect.

  • @katiadjerroud9643
    @katiadjerroud9643 Год назад +1

    hey i keep having error CS1061 stating that vector2 does not contain a definition for GetAxisRaw ! can you please explain how i can fix it
    thank you

    • @Aguyfrom225
      @Aguyfrom225 9 месяцев назад

      Just delete old script file completely and retype it. I had same problem. Might be a space or a capital letter or noncapital letter

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

    25:43 What keyboard key did you press?

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

    Thank you for the lesson! The player moves with inertia. What causes it and how to get rid of it?

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

      Found. This because "yield return null" allows coroutine to work a part of the next frame. So maybe better "yield return new WaitForEndOfFrame();"

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

    The Code Is Malfunctioning. It doesn't recognize Some of the Code. It is showing me the following errors:
    Assets\Scripts\PlayerController.cs(7,13): error CS0246: The type or namespace name 'Vector2' could not be found (are you missing a using directive or an assembly reference?)
    Assets\Scripts\PlayerController.cs(28,22): error CS0246: The type or namespace name 'Vector3' could not be found (are you missing a using directive or an assembly reference?)
    Assets\Scripts\PlayerController.cs(28,5): error CS0246: The type or namespace name 'IEnumerator' could not be found (are you missing a using directive or an assembly reference?)
    Assets\Scripts\PlayerController.cs(7,13): error CS0246: The type or namespace name 'Vector2' could not be found (are you missing a using directive or an assembly reference?)
    Can anyone help me?

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

      Please Help me with this...

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

      I am using Visual studio version 2019.

    • @АнтонБіндовський
      @АнтонБіндовський Год назад

      @@BornToCode75 Hi! Have you added namespace UnityEngine? It looks like VS cann't find the declaration of Vector2 structure.

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

    How did you draw the cloud tiles.after the first video

  • @nickreaper6624
    @nickreaper6624 5 месяцев назад

    How did you assign it to the movement keys???

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

    It took me a half hour to spot that transform.position mistake in 22:30

    • @p.rasmitadora4731
      @p.rasmitadora4731 11 месяцев назад

      I hope you would have elaborated I had to rewatch that part almost 20 times🤧

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

    Can I somehow "block" the character from moving diagonally?

  • @mushycorn4200
    @mushycorn4200 7 месяцев назад

    The move speed option isn't appearing on Unity and most of the commands aren't highlighting in my script. I'm not sure what I've done wrong, as I followed every step to the point I was copying

    • @inoshiibira3251
      @inoshiibira3251 7 месяцев назад

      Remember to save the code. I was stumped with this issue for a while until i remembered it was because i forgot to save it. Also check for capital letters and making sure everything is timed correctly

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

    Great Video

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

    I have a problem :( it’s saying input axis vertical not set up in the console when I start it

  • @siWIBU24
    @siWIBU24 8 месяцев назад

    Can I ask for a Playercontroller script?.....I've tried it many times but it always fails😅

  • @JobbieCivanne
    @JobbieCivanne 7 месяцев назад

    Do you have a document with the code completed and typed so we can compare

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

    how do you get the clouds to look so good

  • @Skirks.Husband
    @Skirks.Husband Год назад

    Hello, my character is showing only the outline not the entire character. How to fix this?

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

    how to move?

  • @the_tree_2010
    @the_tree_2010 Год назад +1

    For some reason, it is giving me 3 errors. any fixes?

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

      same gives me an expression term error, a " ; expected error", and a "} expected" error even though i have the same code

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

      nvm forgot a parenthesis for the while statement

  • @br0ki547
    @br0ki547 9 месяцев назад

    The type or namespace name 'vector3' could not be found (are you missing a using directive or an assembly reference?)
    please help

    • @Aguyfrom225
      @Aguyfrom225 9 месяцев назад

      Capital Vector3. I have problems and what i did was delete the script in the microsoft viz and delete the script on unity. I started over and retyped everything and it works now

  • @jakubklacior1189
    @jakubklacior1189 8 месяцев назад

    Hey i have a question from where dis you get this assets and can i use for comercial use can you give me linki to it if you have

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

    Hi, I've gone through most of this series of tutorials and so far have found it brilliant so thank you for making them!
    Is there any way have character movement be less.. "blocky" - my character moves one grid square at a time. Could it be more responsive? I've changed GetAxisRaw to "input.x = Input.GetAxis("Horizontal");", which allows for movement in a range between 0-1, but it still sometimes keeps moving after I release keys. And horizontal movement just doesn't feel right either.
    Thanks!

    • @Tony-cm8lg
      @Tony-cm8lg Год назад +3

      The way that the tutorial sets up the movement is to basically calculate a starting position and target position and then in the coroutine we calculate the direction and movement speed towards the target position. This means essentially that we aren't actually moving but we are saying "move in this direction by one unit" and the code executes that to move by one unit.
      Another way of doing this (a very simple way) is to use the following code
      private void FixedUpdate()
      {
      float x = Input.GetAxisRaw("Horizontal");
      float y = Input.GetAxisRaw("Vertical");
      input = new Vector2(x, y);
      transform.Translate(input*Time.deltaTime);
      }
      This allows you to move essentially however small a distance you want, not unit by unit

    • @VVorldAWarcraft
      @VVorldAWarcraft 11 месяцев назад

      This code works much better and is easier to understand. How would I go about changing the move speed of this version of the code? @@Tony-cm8lg

    • @miwny
      @miwny 11 месяцев назад

      @@Tony-cm8lg I've done this but I can't seem to change the movement speed on my Player?? Is there something I'm not seeing?

    • @Tony-cm8lg
      @Tony-cm8lg 11 месяцев назад

      I think if you multiply by a constant you can control the speed of the movement. For example, input*Time.deltaTime*2 would move faster I think@@miwny

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

    my charakter is walking to the left autom. What do I do?

  • @cloud252
    @cloud252 Год назад +1

    I don't get how to move the player can anyone tell me , Please qwq

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

    Amazing video, i'm quite new in game dev, im taking it as a hobby, but i'm learning a lot thanks to you

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

      make the layer of the player 1 from the inspector

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

      Hopefully it made sense in the next video when I talk about layers !

  • @Tom-pq5se
    @Tom-pq5se Год назад

    hi, im trying to import the game character in the game scene. but when i trag it into the scene i am only able to see the border of the character and not the texture itself

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

      Click at the character, then at 'order in layer' and put 1 instead of 0.

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

    Hi! Loving the tutorial so far. I have the same code as you, but I can’t move my character. Is there a specific reason for this?

    • @epicgdev
      @epicgdev  Год назад +1

      A lot of people said that the issue was with capitalizing correctly the variables. like MoveX

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

      @@epicgdev I think I did, I checked through all of my code. Thank you so much for the reply though, your tutorials are extremely good for learning. I ended up using another video by “BMo” and used the movement system he used. I loved your video on creating backgrounds, I was up until 4 in the morning creating my map :) I also used your method for making animations

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

    How can I turn this code into a pixel perfect movement?

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

    idk why but my character keeps moving upward. I even tried using the code from the video in the comments. I tried a different keyboard and everything. I'm really at a loss here.

  • @Cyber-Gyn
    @Cyber-Gyn Год назад

    I'm a beginner, please send the code here, I wrote the same as the video, but for some reason it didn't work I get an error Assets\Scripts\PlayerController.cs(35,75): error CS1513: } expected

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

      It's likely that you made some kind of mistake. C# is very strict. I'm extremely new to programming, but I THINK that your error means that the problem is on the row 35 and 75? So check those and also check the rows just before them, so 34 and 74.

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

      have you fixed it? i got the same problem but on 42,112 and that aren't the code linec beacuse i don't even have that many

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

    I need help I can’t find the script in Visual studio

  • @sebastianbryndziar5230
    @sebastianbryndziar5230 11 месяцев назад

    why is my character moving just left and right?

  • @Eboomer123
    @Eboomer123 11 месяцев назад

    i might be dumb but i get about half a second of delay and about half of my key strokes are simply not output through the movement of my character. The code is the exact same as shown.

    • @EchnatonOne
      @EchnatonOne 10 месяцев назад

      It might be the while loop. Try to run it without the while loop in the coroutine. I also have some problems with the loop.

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

    I have a question... Like why my character is going wildly like he move like the flash. Is there any solution?

  • @CodeGAMERQT
    @CodeGAMERQT 5 месяцев назад

    Help i cant see the movment speed

  • @angelkaki5707
    @angelkaki5707 6 месяцев назад

    has anyone wonder how did he managed to get those clouds around the well??? coz its been 20 minutes and I cant figure out how the heck he did that xD

  • @Pipi0-0-7
    @Pipi0-0-7 Год назад

    hi, the movement of the player is delayed, what should i do?

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

      i have the same problem. did you find a way to fix it?

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

    is there anyway to polish the movement

  • @ykwquest
    @ykwquest 10 месяцев назад

    and what about i want to create my own character?

  • @slightshortsmc
    @slightshortsmc 11 месяцев назад

    thx for player movement

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

    My code is the same as yours and i did everything as you, but my character isnt moving

    • @p.rasmitadora4731
      @p.rasmitadora4731 11 месяцев назад +1

      It is due to at 23:29 he changes targetPos to transform.position

  • @saifkhaled1914
    @saifkhaled1914 10 месяцев назад

    Why did you choose coroutine function?

    • @145Jamie
      @145Jamie 10 месяцев назад +1

      I'm wondering the same, much easier ways of moving a 2D character up and down. This just hurt my brain

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

    For some reason my input is inversed.

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

    I tried this code it worked for me:
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class playerController : MonoBehaviour
    {
    public float moveSpeed;
    // Start is called before the first frame update
    void Start()
    {

    }
    // Update is called once per frame
    void Update()
    {
    Vector3 playerInput = new Vector3(Input.GetAxis("Horizontal"),Input.GetAxis("Vertical"),0);
    transform.position = transform.position + playerInput.normalized*moveSpeed*Time.deltaTime;
    }
    }
    well I'm a noob so I don't know much. But i think it's fine for now

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

      hi, im still learning C# and game dev thingy. and i want to ask, is that playeInput.normalized is to make diagonal movement have equal speed to horizontal and vertical??
      thank you

    • @jojinodi3417
      @jojinodi3417 11 месяцев назад

      @@itsbps Yes it'll make diagonal movement the same speed as the vertical and horizontal instead of adding them both for the diagonal movement

    • @ryuz__aki
      @ryuz__aki 4 месяца назад

      Thanks

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

    nvm it seems to work now but im moving too fast