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

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

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

  • @supraliminal283
    @supraliminal283 8 месяцев назад +91

    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.

    • @ivancamargod7819
      @ivancamargod7819 7 месяцев назад +3

      thank you

    • @PankakesTheReal
      @PankakesTheReal 5 месяцев назад +2

      YES thank you

    • @rijulduggal5584
      @rijulduggal5584 3 месяца назад +4

      "no one will help you on the internet" my ass

    • @j.d.zilkey7799
      @j.d.zilkey7799 3 месяца назад +2

      good man

    • @vipereaper
      @vipereaper 2 месяца назад +5

      Or in my case change the z value in position until you can see your character

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

    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  Год назад +4

      Thank you very much! It made my day!

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

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

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

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

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

    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 Год назад +6

    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!

  • @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  Год назад +4

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

  • @rafirizqullahramadhan6257
    @rafirizqullahramadhan6257 11 месяцев назад +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

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

    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 9 месяцев назад

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

    • @jaypalmer0616
      @jaypalmer0616 9 месяцев назад +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 5 месяцев назад

      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 2 месяца назад

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

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

    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!

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

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

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

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

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

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

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

      You're very welcome!

  • @kizuma_
    @kizuma_ 7 месяцев назад +5

    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 7 месяцев назад

      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_ 7 месяцев назад +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

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

      Thanks so much for this!

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

      How would I animate the character sprites though?

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

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

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

    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!

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

    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 Год назад +3

      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 Год назад +8

      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 Год назад +2

      ​@@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 8 месяцев назад +1

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

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

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

  • @MiguelPerez-ui2gy
    @MiguelPerez-ui2gy Месяц назад

    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.

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

    Good series so far! Nice level-flexible delivery

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

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

  • @miaoumixed4268
    @miaoumixed4268 Год назад +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  Год назад

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

  • @matthewlavigueur6210
    @matthewlavigueur6210 7 дней назад

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

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

    nice, looking forward for next tutorial

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

      More coming soon! Thank you for the support!

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

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

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

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

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

    Love this tutorial , thanks for making it simple

  • @nemofeducis
    @nemofeducis 10 месяцев назад +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 9 месяцев назад

      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 7 месяцев назад

      @@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 12 дней назад

      Thanks

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

    These are excellent tutorials

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

    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.

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

    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.

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

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

  • @NoahElkins-pe4lz
    @NoahElkins-pe4lz 4 месяца назад +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

    • @user-wx7dv4fn5m
      @user-wx7dv4fn5m 2 месяца назад

      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 5 месяцев назад

      I got same problem

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

      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;

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

    Thats exactly what i needed :) thanx bro

  • @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 7 месяцев назад +1

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

  • @omarpokemon9626
    @omarpokemon9626 7 месяцев назад +2

    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 6 месяцев назад +2

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

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

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

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

    thank u for created this series

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

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

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

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

      You shouldn't have to worry about your Z position in a 2D game.
      In a 2D game, the objects are rendered in the order you tell it to render. Unity simplifies this by letting you specify the 'Order in Layer'.
      Go to 'Additional settings' in your objects and look for 'Sorting Layer' and 'Order in Layer'.
      Leave all your objects on the default layer and just adjust the 'Order in Layer'.
      Example: My background and my sprite are both on the default sorting layer. The background's 'Order in Layer' is 0 and the sprite's 'Order in Layer' is 1.

  • @justicedunne6736
    @justicedunne6736 4 месяца назад +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?

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

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

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

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

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

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

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

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

  • @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 2 месяца назад

      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.

  • @nhuttran9757
    @nhuttran9757 11 месяцев назад +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

  • @Delta_Player_0ne
    @Delta_Player_0ne 9 месяцев назад +2

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

  • @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 7 месяцев назад

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

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

    my character moves very slow and delayed

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

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

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

    Great Video

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

    how to move?

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

    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

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

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

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

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

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

    Thanks 🎉

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

    Help i cant see the movment speed

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

    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 2 месяца назад

      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

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

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

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

    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?

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

    thx for player movement

  • @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 5 месяцев назад

      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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    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.

    • @user-mo7jl2nl3v
      @user-mo7jl2nl3v Год назад

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

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

    why is my character moving just left and right?

  • @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 5 месяцев назад

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

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

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

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

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

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

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

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

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

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

      nvm forgot a parenthesis for the while statement

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

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

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

    Couldn't you simply do "if input.x+input.y > 0" for the Move functrion? why bother doing all that math when you already know how much you're transforming the body by (the values of input.x and input.y)

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

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

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

    how do you get the clouds to look so good

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

    nvm it seems to work now but im moving too fast

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

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

  • @user-lh6vp4ro3w
    @user-lh6vp4ro3w 6 месяцев назад

    and what about i want to create my own character?

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

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

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

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

    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 6 месяцев назад

      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.

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

    For some reason my input is inversed.

  • @Tom-pq5se
    @Tom-pq5se 10 месяцев назад

    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 10 месяцев назад

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

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

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

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

    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

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

    my character always appears behind the background, anyone know how to fix this?
    Edit: so after toggling a bunch of things, i figured out you just need to create a new layer on sorting layers, then put it behind the layer the player is on

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

      A simpler way is in the inspector. Select your player, then in the inspector under Additional Settings there is "Order in Layer" setting. If you change that from 0 to 1, the player layer will be ordered after the background layer and will be visible in the scene.

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

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

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

      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

  • @user-yt3kx9pm7e
    @user-yt3kx9pm7e Месяц назад

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class PlayerController : MonoBehaviour
    {
    public float moveSpeed;
    private bool isMoving;
    private Vector2 input;
    private Animator animator;
    private void Awake()
    {
    animator = GetComponent();
    }
    private void Update()
    {
    if (!isMoving)
    {
    input.x = Input.GetAxisRaw("Horizontal");
    input.y = Input.GetAxisRaw("Vertical");
    Debug.Log("This is input.x" + input.x);
    Debug.Log("This is input.y" + input.y);

    if (input.x != 0) input.y = 0;
    if (input != Vector2.zero)
    {
    animator.SetFloat("moveX", input.x);
    animator.SetFloat("moveY", input.y);
    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;
    }
    }

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

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

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

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

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

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

    is there anyway to polish the movement

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

    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 9 месяцев назад +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 7 месяцев назад

      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 6 месяцев назад

      @@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 6 месяцев назад

      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

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

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

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

    25:43 What keyboard key did you press?

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

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

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

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

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

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

    For some reason i can't type !