Grid Based Movement in Unity

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 ก.ย. 2024
  • Learn how to use grid-based movement in unity!
    Get the starter project files at drive.google.c...
    Get my Complete 2D Platformer course at www.udemy.com/...
    Join GamesPlusJam 3 at itch.io/jam/ga...
    Don't forget to hit that like button and if you'd like to see more gaming goodness then subscribe for more!
    Support the show by pledging at / gamesplusjames
    And you can also find me on twitter and facebook!
    Twitter - / gamesplusjames
    Facebook - / gamesplusjames
    Outro music "Theme for Harold var 1" by Kevin McLeod - www.incompetech...

ความคิดเห็น • 238

  • @Dezomm
    @Dezomm 4 ปีที่แล้ว +66

    If anyone has problems with the OverlapCircles not working to block player movement into "illegal" places as defined by your colliders on the stopsMovement layer, try the following: In the grid object child "Colliders" (or whatever you named it) that you use for defining where colliders should be, make sure Composite Collider 2D has Geometry Type set to Polygons, **not** Outlines. At least that worked for me on Unity 2020.1.

    • @Taterzz
      @Taterzz 3 ปีที่แล้ว +6

      thank you for this, i had this exact issue. i changed the style from outline to polygons during testing to fix it, but i should have looked here first and saved my ass like 2 hours of frustration.

    • @VerTheBonBonVoni
      @VerTheBonBonVoni 2 ปีที่แล้ว

      @@Taterzz Same here.

    • @nunnyu
      @nunnyu 2 ปีที่แล้ว +2

      You're a lifesaver man! How did this comment just pop up just as I messed it up lol

    • @LeandroAuzier
      @LeandroAuzier 2 ปีที่แล้ว +1

      i almost got happy seeing this comment, however it didn't work in my case, only horizontally, if i press vertical keys the player pass through walls :(.... Unity 2021.3.5f

    • @shinkouhai919
      @shinkouhai919 2 ปีที่แล้ว

      this a time-saving comment! thanks for the knowledge

  • @admulberg
    @admulberg 4 ปีที่แล้ว +34

    Great tutorial! Thank you
    Here is a slightly refactored version of the PlayerController script:
    public class PlayerController : MonoBehaviour {
    [SerializeField]
    private float speed = 5;
    [SerializeField]
    private Transform movePoint;
    [SerializeField]
    private LayerMask obstacleMask;
    void Start() {
    movePoint.parent = null; // Detach partent
    }
    void Update() {
    float movementAmout = speed * Time.deltaTime;
    transform.position = Vector3.MoveTowards(transform.position, movePoint.position, movementAmout);
    if (Vector3.Distance(transform.position, movePoint.position)

    • @sol15_
      @sol15_ 3 ปีที่แล้ว

      What does [SerializeField] do

    • @_juliakp1_
      @_juliakp1_ 5 หลายเดือนก่อน

      thank you!!

    • @farzbz987
      @farzbz987 3 วันที่ผ่านมา

      @@sol15_ Already 3 years, I assume you already know it but, just in case, that does show you the values of a private and protected variable on the inspector so you don't have to change it on the code.

  • @thebadshave503
    @thebadshave503 4 ปีที่แล้ว +82

    3:02 See when you say it, you're "game developer", when I say it I'm "A bad step-dad". Double standards.

    • @unity3dgamedevelopers954
      @unity3dgamedevelopers954 4 ปีที่แล้ว

      Turn based strategy tutorial like Heroes of Might and magic
      udemy.com/course/turn-based-strategy-game-development/learn/lecture/21513708?start=0#overview

    • @SirDrasticG
      @SirDrasticG 3 ปีที่แล้ว +2

      took me a while lmao

  • @Kurokage130
    @Kurokage130 4 ปีที่แล้ว +10

    This video is simple in complexity, yet deep in depth.
    This type of content is exactly what people need, thus you're a hero and I thank you!!!

  • @thebadshave503
    @thebadshave503 4 ปีที่แล้ว +13

    I've been watching your tutorials for a long time and I have to say you're getting really better at condensing concepts. Not that the the older tuts were bad. I learned a lot from them, but this format is really helpful.

  • @noahborden7684
    @noahborden7684 2 ปีที่แล้ว +3

    Protip you can adjust the tile size by multiplying the axis in movePoint.position by your tile size

  • @metall7331
    @metall7331 4 ปีที่แล้ว +4

    The collision technique was really buggy for me so I placed four triggers around the character to detect obstacles instead. Thanks for the video!

    • @edgarlawrence9191
      @edgarlawrence9191 4 ปีที่แล้ว

      hey bro, can i see your script of your four triggers? cause im newbie in the gameDev
      you can send me on my email edgarlawrence96@gmail.com
      much appreciatied :D

  • @Konslufius
    @Konslufius ปีที่แล้ว +1

    Awesome, you can also use that system in a reversed way to have a follower system. Every time I move, my character leaves a "token" which is tracked by my follower. The follower moves towards that token until he is on top of it. When I move again, the token's transform is equal to my current position and my follower moves towards that token again. I called the token "lastposition". Works surprisingly well.

  • @sykoo
    @sykoo 4 ปีที่แล้ว +61

    Woop woop! This is fantastic! =D

    • @gamesplusjames
      @gamesplusjames  4 ปีที่แล้ว +3

      Thanks Sam :)

    • @maruf16khan
      @maruf16khan 4 ปีที่แล้ว +3

      Sykoooo! 😁😁

    • @se9979
      @se9979 4 ปีที่แล้ว +1

      @@gamesplusjames hey, is it ok for you to give me a hand?

  • @royvictorgagarin55
    @royvictorgagarin55 2 ปีที่แล้ว +1

    this is the simplest grid movement I've ever watched so far. thank you :)

  • @turkeyjerkey
    @turkeyjerkey 3 ปีที่แล้ว +22

    Excellent tutorial, as always! Have you considered doing a tutorial on mouse-click based grid movement, with your movement range shown by highlighted tiles in your grid (e.g., for a turn-based game)? Even cooler if it also showed your attack range (e.g., for ranged or magic attacks). Thanks for all your excellent tutorials and courses (I've purchased 5 of them on Udemy)!

  • @LobsterWithABagel1629
    @LobsterWithABagel1629 ปีที่แล้ว

    I Figured It out! If You are Struggling with this issue too, Create an empty Object called player, then attach the movepoint and sprite to it.

  • @LordMaskin
    @LordMaskin 4 ปีที่แล้ว +3

    I bought your Udemy for RPG's but this is really what I was looking for.

  • @IamDaveDev
    @IamDaveDev 10 หลายเดือนก่อน

    Something I recommend is moving the overlapcircle check to be outside of the key check. Also put both x and y axis in the vector3.

  • @krekk2751
    @krekk2751 4 ปีที่แล้ว +3

    ok this was the best tutorial I have seen so far, clean and easy. Loved it.

  • @oicmorez4129
    @oicmorez4129 4 ปีที่แล้ว +2

    Alright, that's a nice, easy and clean tutorial
    thanks for making my dreams easier

  • @BeanDancing
    @BeanDancing 3 ปีที่แล้ว +3

    Awesome! I'd been struggling to find a good tutorial on this! Very simple and concise but still very clear and informative!

  • @HaydenTheJayden
    @HaydenTheJayden 2 ปีที่แล้ว

    Honestly one of the best tutorials I've watched

  • @khiemle6441
    @khiemle6441 ปีที่แล้ว

    Bro you're so good at explaining, what a rare gem

  • @thecoldlemonade3532
    @thecoldlemonade3532 3 ปีที่แล้ว

    that felling when your code works first time is awesome

  • @thedude110
    @thedude110 4 ปีที่แล้ว +4

    Could you make a video with more mechanics based on grid movement? Eg pushing and pulling objects that should also move on grid

    • @MoonLiteNite
      @MoonLiteNite 4 ปีที่แล้ว

      What i am trying to do on my first go with unity, not having much luck :( I can easily force the object to move in a single direction, but i cant figure out a way to get the direction based on the side the object was triggered at.

  • @himanshujangid5975
    @himanshujangid5975 3 ปีที่แล้ว +1

    If you are facing the problem of Input Delay,
    Change Horizontal And Vertical Axis's Sensitivity to 10 and Gravity to 10 in
    Edit>Project Settings>Input Manager
    It will fix the issue

  • @MoonLiteNite
    @MoonLiteNite 4 ปีที่แล้ว +6

    @2:00 so you totally skipped on how to create the moviePoint as a child under the player. it was just "ready" to go before you started making the video haha. In case anyone is wondering, right click on the left pane, "add object"

  • @SonicNKnux
    @SonicNKnux 2 ปีที่แล้ว

    Fantastic work, you went into great detail at a comprehensive pace for others to follow along. That's not a common skillset; you're a great teacher!

  • @ir3dyplayz78
    @ir3dyplayz78 4 ปีที่แล้ว

    Thank you u finally made it!!! It's been killing me I I stop making my game cause I couldn't figure out grid based movement

  • @nanardeurlambda
    @nanardeurlambda 2 ปีที่แล้ว

    8: 27 after having tried this movement system, I am now convinced there potential for a rage game here somewhere.

  • @christorsss
    @christorsss 4 ปีที่แล้ว

    The best explanation of if and else if. Thank you in advance!

  • @stefan429
    @stefan429 3 ปีที่แล้ว

    afaik mathf.abs is more expensive than just getting the inputs into a vector and normalizing it, great vid :)

  • @tinboiter1414
    @tinboiter1414 2 ปีที่แล้ว +2

    How come the grid size plays no role in this?

  • @gianlucabianchi2650
    @gianlucabianchi2650 4 ปีที่แล้ว

    Love it! I'm happy that works in Isometric as well.

  • @TriDeapthBear
    @TriDeapthBear 4 ปีที่แล้ว +7

    4:38 could you instead do
    if (Input.GetAxisRaw("Horizontal") != 0f)
    Is that inefficient in any way? Because that's what I've been doing for a while :P nice tutorial though!

    • @gamesplusjames
      @gamesplusjames  4 ปีที่แล้ว +6

      That'll work nicely on keyboard for sure but if using a controller it be a little overly sensitive :)

  • @KillerGameDev
    @KillerGameDev ปีที่แล้ว

    If I could add one little tidbit...I think after you check distance, you should reset player transform to the new expected transform. If you are truly doing a grid, you can see that every movement makes the character more and more off the grid. Especially if you are nit-picky and like to put the final transform at the bottom. I was like "no! he put...the transform...at the top!!!!!! Whyyyyy!? he did his figuring after he did the transform!!! whyyyyy!?!?!" which is okay I just ran into the issue where everytime I would hit the button, the character was a little more off the grid. Teleporting him after reaching an okay error offset helped and is unnoticeable to the user.

  • @evenaxin3628
    @evenaxin3628 2 ปีที่แล้ว

    I made my own version of moveTowards, transform.position = (transform.position * moveSpeed + movePoint.position) / (1+moveSpeed); which I use because it's a bit smoother.

  • @fatboy2867
    @fatboy2867 4 ปีที่แล้ว +6

    If I want the movement to be continuous like in pacman without needing to hold the key down, what do I need to change?

    • @unity3dgamedevelopers954
      @unity3dgamedevelopers954 4 ปีที่แล้ว

      Turn based strategy tutorial like Heroes of Might and magic
      udemy.com/course/turn-based-strategy-game-development/learn/lecture/21513708?start=0#overview

    • @anomalocarissupremo3909
      @anomalocarissupremo3909 4 ปีที่แล้ว

      set the input to a vector2 variable and only update the variable when the input is not (0, 0)

    • @se9979
      @se9979 4 ปีที่แล้ว +1

      its probably not that but you could try "re-parenting" the movePoint

  • @jonasmyhrrefseth5720
    @jonasmyhrrefseth5720 4 ปีที่แล้ว +7

    You should probably use something like git, instead of a Zip hosted on Google Drive. Github is free.

  • @WanderyenErin
    @WanderyenErin 2 ปีที่แล้ว

    Oh I was looking exactly for this! Thanks for sharing!

  • @DiegoTube85
    @DiegoTube85 4 ปีที่แล้ว +2

    what if I want the hero to move only if he's facing the same direction of the input and just change direction standing still otherwise?

  • @Zelager
    @Zelager 4 ปีที่แล้ว +1

    Great tutorial, James! This was the first time I've done much with Unity and this was concise and easy to understand.

  • @craigmobey954
    @craigmobey954 4 ปีที่แล้ว

    Exactly what I needed in nice digestible pieces!

  • @Muftaay
    @Muftaay 4 ปีที่แล้ว +1

    very clear instructions and explanations. thank you!

  • @viscarious1
    @viscarious1 4 หลายเดือนก่อน

    This was so helpful thank you!
    Have you had any luck getting this sort of movement in the "new" input version?

  • @TheToneBender
    @TheToneBender 4 ปีที่แล้ว +3

    Crud... I'm also following Brackey's top down movement tutorial and now I can't figure out how to combine his code with this grid based code :l

    • @SoupCanMafia
      @SoupCanMafia 4 ปีที่แล้ว

      I think that Brackey, as good as he is, does usually have his projects using pre-made assets. Like for my game engines class, I used a pre-made character controller asset to control the character. Though I am certain he has a video about grid-based movements, I'm uncertain if it's in the top-down series.
      At the moment, while I have basic experiences with coding, I can't necessarily help you. And the best advice I could give you is to cross-reference this video and the Brackeys video, see if you can rewire the code to make movement more grid-based.

  • @fv4202x
    @fv4202x 4 ปีที่แล้ว

    thanks so much i thought its impossible lol. i think that movePoint event is a so genious idea.

  • @nic54654
    @nic54654 4 ปีที่แล้ว

    I recognize that voice! I did one of your platformer tuts a while back, awesome video btw, just what I needed, thanks! ;D

  • @LordMaskin
    @LordMaskin 4 ปีที่แล้ว +2

    I would love to know how to do this and interact with objects using unity's Isometric maps. I keep trying to detect objects using 2dRayCast but it never seems to work very well.

  • @DT-hb3zu
    @DT-hb3zu 2 ปีที่แล้ว +2

    This was amazing! Thank you for this. I do have a question as well; Is there a reason to use Vector3 over Vector2 in this case?

    • @michaelm.7728
      @michaelm.7728 2 ปีที่แล้ว

      It looks like most of transform.position and movePoint.position require a Vector3

  • @8Blits
    @8Blits 4 ปีที่แล้ว +5

    Love the tutorial!

  • @klibe
    @klibe 3 ปีที่แล้ว

    Thanks man! I've been looking for this!

  • @Cvusmo
    @Cvusmo 4 ปีที่แล้ว +3

    I'm using the new input system. I've managed to make my player move and be animated. The problem is he moves only one grid square left, right, up, or down, but won't move around the "map." I cant figure out the solution...

    • @gamesplusjames
      @gamesplusjames  4 ปีที่แล้ว +4

      are you setting the transform.position using = instead of +=? Using += will add the new vector to your position but just using = will set the position directly as your input :)

    • @Cvusmo
      @Cvusmo 4 ปีที่แล้ว +2

      gamesplusjames I was looking at operators and wondering if that would fix it haha. I knew it was something simple. Thanks man!

  • @user-tf5hb7om9z
    @user-tf5hb7om9z 4 ปีที่แล้ว

    this video is just what I wanted to learn. thanks!

  • @danielpereira6660
    @danielpereira6660 4 ปีที่แล้ว

    Inspired by Hopia Tale on mobile? I just found that game last week and this is what the entire game is based around. Cool tutorial might try it out later.

    • @gamesplusjames
      @gamesplusjames  4 ปีที่แล้ว

      It's more inspired by classic RPG movement :) Can't say I've heard of Hopia Tale unfortunately :)

  • @AlexKidmann
    @AlexKidmann ปีที่แล้ว

    Thanks so much for the help, your video is very clear and well explained ! :D

  • @digis_monkey_king
    @digis_monkey_king 2 ปีที่แล้ว

    Like always, great explanation! very easy to understand and interesting...

  • @Phenix2663
    @Phenix2663 3 ปีที่แล้ว

    serious life saver been searching for this for abit i am terrible with code XD

  • @MarceloCSC
    @MarceloCSC 4 ปีที่แล้ว +1

    Extremely helpful and to the point tutorial, thanks a lot!!
    Can someone just please help me understand WHY does this work?? I mean, I followed the whole thing and it works like a charm, I just can't wrap my head around WHY it's actually working and the character is never landing outside the grid.
    Thanks in advance!

    • @fregyt
      @fregyt 4 ปีที่แล้ว

      It's set to move a specific distance and new movement cannot be requested until that requested movement has been completed. This limits the ability to move diagonally as well, as it is only allowed to execute one movement direction at a time. Here is an order of operations for you:
      The movepoint teleports to a location that's specifically in the centre of a grind square.
      The Player sprite moves toward the movepoint
      When the player sprite and the movepoint have the same x, y values, a new movement for the movement can be done, restarting the cycle.
      Hope this made sense

  • @general_md
    @general_md 4 ปีที่แล้ว +1

    How can i make the player that it continuously moves till it collides or another key is pressed but only turning at a grid?

  • @hernandeztorresederjairdej5564
    @hernandeztorresederjairdej5564 3 ปีที่แล้ว

    If you are having problems with the collisions, try to save the input axis value into variables and then use them in the rest of the code
    //transform.position = Vector3.MoveTowards(transform.position, MovePoint.position, MoveSpeed * Time.deltaTime);
    float horizontalInputValue = Input.GetAxisRaw("Horizontal");
    float verticalInputValue = Input.GetAxisRaw("Vertical");
    //if (Vector3.Distance(transform.position, MovePoint.position)

  • @legitchrisv
    @legitchrisv 4 ปีที่แล้ว +3

    Great video! So, what if we don't want the user to hold down movement, rather, they're limited to one tile movement per press similar to rogue-likes?

    • @gamesplusjames
      @gamesplusjames  4 ปีที่แล้ว +2

      you could store the inputs in a variable and then check that when you're pressing input that it doesn't match what was pressed on the previous frame

    • @BenBonk
      @BenBonk 4 ปีที่แล้ว +12

      For anyone stumbling across this comment and wanting a solution to this I would recommend making a bool that needs to be true whenever you move and every time you move start a co-routine setting that variable to false, then using WaitForSeconds() and put in the time you wan't to have between inputs, and then set it to true. This was a very easy solution to implement for me.

    • @lilsquid8880
      @lilsquid8880 4 ปีที่แล้ว

      That’s actually a good idea I’m going to use that

  • @NTC
    @NTC 3 ปีที่แล้ว

    awesome, can u please do a series of Unity for beginners? you have great teaching skills

  • @babasheep2828
    @babasheep2828 2 ปีที่แล้ว +1

    Hey i have an issue. The collisions are only working on the X axis, not the Y, so I cant go through the side borders, but I can go through the top and bottom ones. Any ideas?

  • @yogamike406
    @yogamike406 4 ปีที่แล้ว

    This is exactly what I needed! Thank you so much :)

  • @gustavofelix257
    @gustavofelix257 2 ปีที่แล้ว

    Excellent explanation. You are Amazing

  • @adammickiewicz7818
    @adammickiewicz7818 ปีที่แล้ว

    Helpful as always, thanks a lot!

  • @NightRunStudio
    @NightRunStudio 3 ปีที่แล้ว

    So helpful. Thanks for the great videos.

  • @williamtoscani
    @williamtoscani 4 ปีที่แล้ว

    Really great video, it's what i was searching for!
    Could you make a video about enemy player find system?

  • @isol8id
    @isol8id ปีที่แล้ว

    To anyone else with problems with the movePoint transform passing into or through things on the StopMovement layer - try changing the use of Time.deltaTime to Time.fixedDeltaTime, it helped me anyway!

  • @shakenbake6773
    @shakenbake6773 4 ปีที่แล้ว +1

    This is such a great tutorial, exactly what i was looking for, thank you! I have a question though. How did you pull the player sprite out of that sprite sheet? I was trying to slice out the blue guy but then i messed up all my tiles. It seems like i can only get it to slice by 16x16 squares, but somehow in your project i get all the 16x16 tiles AND a 18x26 player?

  • @oystercam1040
    @oystercam1040 3 ปีที่แล้ว +1

    hi, can you plz do a video showing how to do a board game on unity, where can the character choose to go or not to the other way? like a square with a line on de midle where they walk on it based on a dice movement..it would be really amazing ;v;

  • @durbanpoison8831
    @durbanpoison8831 4 ปีที่แล้ว

    Awesome tutorial! Thank you!

  • @daynger8085
    @daynger8085 11 หลายเดือนก่อน

    Great tutorial! question about the no-diagonal script: If I wanted to make it so that horizontal movement does not take precedence over vertical movement or vice versa how would you do it? I'm trying to make an rpgMaker style game where your most recent input is the one that takes priority Thanks!

  • @hillelywood5118
    @hillelywood5118 ปีที่แล้ว

    i keep getting this error "The variable movePoint of Player has not been assigned.
    You probably need to assign the movePoint variable of the Player script in the inspector." and i have no idea what im supposed to do

  • @tigranavagyan1587
    @tigranavagyan1587 ปีที่แล้ว

    Thank you very much!!!

  • @matthewfiorentino4727
    @matthewfiorentino4727 4 ปีที่แล้ว +2

    My movepoint keeps getting "trapped" by the various colliders on my map - can anyone help? Is it possible I've set the tilemap colliders up wrong? I'm using edge colliders for my map boundaries, but the movepoint seems to pass beyond the boundary even though the player doesn't pass beyond the collider, but since the movepoint is outside, it gets "hooked" there and can't come back into the safe zone.
    The tilemap colliders also seems to interpret the shape of the pixel object rather than creating a box the size of a tile, and it creates narrow spaces where the player can't pass. For example, a bed in a room takes up one tile + a little bit of the tile above it and a little bit of the tile below it. So depending on the buffer I set, either I can't access the tiles above and below it at all, or the movepoint gets hooked into the bed collider. Not sure if this makes sense...

    • @tixa4651
      @tixa4651 3 ปีที่แล้ว

      I had the same problem, but u asked it 6 months ago and no answer :(

    • @Amine-dlmr
      @Amine-dlmr 2 ปีที่แล้ว

      @@tixa4651 2 years

  • @johnsknows3135
    @johnsknows3135 11 หลายเดือนก่อน

    excellent thank you!

  • @navelak
    @navelak 3 ปีที่แล้ว

    awesome! thanks man, excellent job

  • @tetelp7656
    @tetelp7656 2 ปีที่แล้ว

    Thankl you a lot bro your videos are great!

  • @feliscape
    @feliscape 2 ปีที่แล้ว

    For some reason the movePoint still gets moved when theres an obstacle ahead. I did add a rigidbody and collider to it because I wanted gravity and otherwise it didn't work well.

  • @PrincessPotion
    @PrincessPotion 3 ปีที่แล้ว

    Super useful, thank you so much! One question that I had though. I set up the LayerMask for the tilemap colliders and that works beautifully. I was wondering if I could do similar for a non-tilemap layer, such as enemies so the player can't move through them too? I tried adding an Enemy layer to the mask in the inspector and setting the enemies to that layer; however, the player still walks through them but is still blocked by the tilemap colliders correctly. Any ideas?

  • @austinsehgal8683
    @austinsehgal8683 2 หลายเดือนก่อน

    Excuse me, what template did you use to creating this project @gamesplusjames ?

  • @EvanOdson
    @EvanOdson 4 ปีที่แล้ว +1

    I am able to get the grid based movement going, and I am now on the step of animating. I am working on a Pokemon clone with this tutorial, so I want an animation going left, right, up, and down. Since this code is a bit complicated, I'm not quite sure how to tell the animator to play a walking left animation when I'm pressing left. Any advice would be much appreciated. Fantastic tutorial! :)

    • @tclowe9280
      @tclowe9280 4 ปีที่แล้ว

      I had the same issue for a few days, what I ended up doing was watching some of his other videos, and adapted that animation system, and one that Brackeys(? maybe?). Basically it takes your input and turns that into something you can then put into the unity Animator blend tree. His tutorial used a bool for transition between idle and moving, and I had a 4 direction idle, so I just sent over the data and set a movement threshold I think. I'm really new at this so I'm sure there are a dozen better ways of doing this, but this is what I got to work for me.
      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;
      public class TileMovement : MonoBehaviour
      {
      public float moveSpeed = 5f;
      public Transform movePoint;
      public LayerMask whatStopsMovement;
      public Animator animator;
      //private bool playerMoving;
      private Vector2 lastMove;
      private Rigidbody2D myRigidBody;
      Vector2 movement;
      // Start is called before the first frame update
      void Start()
      {
      movePoint.parent = null;
      myRigidBody = GetComponent();
      DontDestroyOnLoad(transform.gameObject);
      }
      // Update is called once per frame
      void Update()
      {
      //playerMoving = false;
      transform.position = Vector3.MoveTowards(transform.position, movePoint.position, moveSpeed * Time.deltaTime);
      if (Vector3.Distance(transform.position, movePoint.position)

  • @ironphan24
    @ironphan24 2 ปีที่แล้ว

    Excellent! Thanks so much :)

  • @LobsterWithABagel1629
    @LobsterWithABagel1629 ปีที่แล้ว

    How can I make the player's head not collide with anything

  • @zulesplkx478
    @zulesplkx478 2 ปีที่แล้ว

    Use it to ya advantage im bent n focused

  • @ms1-Alex
    @ms1-Alex 10 ชั่วโมงที่ผ่านมา

    8:57 my character still moves blazing fast
    Why?

  • @coldramen7095
    @coldramen7095 4 ปีที่แล้ว

    very good tutorial.

  • @LobsterWithABagel1629
    @LobsterWithABagel1629 ปีที่แล้ว

    I need help with the head, I don't want the head to collide with objects. Does anybody know how to fix this?

  • @neisef
    @neisef 3 ปีที่แล้ว

    Sorry for not knowing but what is the Player Move Point exactly? Is it a sprite? An empty 2d object? I don't know what to click on Unity to make one.

  • @user-rp8vl5jl9c
    @user-rp8vl5jl9c 4 ปีที่แล้ว

    How could I visualize the radius of the circle which is checking ahead for other colliders ?

  • @danielleanderson6371
    @danielleanderson6371 ปีที่แล้ว

    I rewrote Update() to prevent "corner-cutting" on diagonal movement, so your character can properly walk around walls instead of phasing through them like a ghost:
    void Update()
    {
    transform.position = Vector3.MoveTowards(transform.position, movePoint.position, moveSpeed * Time.deltaTime);
    if (Vector3.Distance(transform.position, movePoint.position)

  • @gadgetboyplaysmc
    @gadgetboyplaysmc 4 ปีที่แล้ว

    Thanks for the tutorial james! One question.
    What's the difference between Input.GetAxisRaw and Input.GetAxis?
    I looked at the docs but I'm not exactly the most literate person so I want to clarify.
    Does Raw mean it gives you ONLY -1 and 1
    while GetAxis gives you floating point values like 0.98892?
    Also... will this still work if the sprites are scaled up?

    • @fregyt
      @fregyt 4 ปีที่แล้ว +1

      The GetAxisRaw is the raw input value from the input, no smooting. The GetAxis is slightly smoothed, which is not wanted in this case.

  • @altf4968
    @altf4968 4 ปีที่แล้ว

    Hello! How did you setup your grid that if player is in the center of grid of one tilemap, his x and y is whole number. Mine is allways .5. Lets say x is 1.5 and y is 5.5 etc.

  • @viscerallyfemme
    @viscerallyfemme 4 ปีที่แล้ว

    Im having issues with blocking movment and tilemaps, gameobjects on the blocking layer stops the movement a tilemap on that layer wont. Any suggestions on why that is?

  • @_g_r_m_
    @_g_r_m_ 4 ปีที่แล้ว

    Great tutorial!!

  • @Amine-dlmr
    @Amine-dlmr 2 ปีที่แล้ว

    hey, my character still passes through walls and stuff, i use a empty game object to wich i put some box colliders then assigned the whatblocksmovement Layer to, i cant use " normal" tilemap colliders because my map is made out of squares. Can anyone help me? thx

  • @stardust4089
    @stardust4089 3 ปีที่แล้ว +1

    What art assets is this project using?

  • @SyreniteyGaming
    @SyreniteyGaming 4 ปีที่แล้ว

    How come the speed variable doesn't seem to affect my characters speed? No matter what its set to it just flys around the tilemap

  • @ticketforlife2103
    @ticketforlife2103 2 ปีที่แล้ว

    How to implement this, but make the character slide the tiles until it hits an obstacle?

  • @SimpSimpleton
    @SimpSimpleton 3 ปีที่แล้ว

    for some reason the animations aren't working for me. it freezes while the button is being held.

  • @CentarPede1
    @CentarPede1 2 ปีที่แล้ว

    Hello, new programmer here.
    Quick question, how would you get the game object of the obstacles (things that stop your movement) if you wanted to be able to destroy them or something?
    Thanks!

  • @nunfununcia
    @nunfununcia 4 ปีที่แล้ว

    I have a probably stupid problem, my player does not move to the last square to the right or down, it is as if a phantom square is preventing movement, to the right and upwards it moves normally. Can someone tell me where the problem is? I'm using version 2020.1.0f1 of unity + visual studio code.