Creating a Diablo Like Click To Move System in Godot 4

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 ก.ค. 2024
  • Subscribe and learn more from me about Game Development and Programming!
    In this video, we talk about how to make a point to click move system inside Godot 4
    RESOURCES
    Source: github.com/finepointcgi/Click...
    BE MY FRIEND:
    🐦Add me on Twitter: / finepointcgi
    Check out my Website: finepointcgi.io/
    Trello of Upcoming Tutorials: trello.com/b/cJWPaVyV/godot-t...
    You can support me on Patreon: / finepointcgi
    Hang Out with the Guys on Discord: / discord
    TIMESTAMPS
    00:00 - Start
    00:59 - Getting Into Godot
    01:31 - Adding a Nav Mesh and How To Set It Up
    05:45 - Adding a Camera To Be Able to Raycast From
    06:46 - Getting Into Code
    15:00 - Fixing a Bug
    17:55 - Discussing What Comes Back
    21:52 - Fixing Our Crash
    23:34 - Fixing Our Environment
    24:06 - Fixing the Character Not Going Directly on Top of Your Mouse
    24:51 - Fixing Our Navigation Area
    25:17 - Making Our Character Face the Correct Direction
    28:17 - Outro and Why I Haven't Been Posting Much
    MUSIC
    Music provided by TheRelaxedMovement.
    Check it out here: / therelaxedm...​
    HASHTAGS:
    #Godot4 #ClickToMove #gamedev
    ABOUT MY CHANNEL:
    I've been a software developer for over 7 years. I've worked in the game industry for 3 of those years. This channel is used for news on the gaming\programming industry and for tutorials for game\programming development.
    Creating a Diablo Like Click To Move System in Godot 4

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

  • @johnpopilek
    @johnpopilek 3 หลายเดือนก่อน +27

    Just in case anyone comes by this video and has issues like I did (I'm using 4.2.1)
    Line 12 changed to:
    if(navigationAgent.is_target_reached()):
    line 18 changed to:
    var targetPos = navigationAgent.target_position

  • @vila4480
    @vila4480 10 หลายเดือนก่อน +6

    Wow this has got to be one of the best tutorials I've ever done. Thank you for not skipping the code fixes when you made mistakes.
    I'm moving from Unity to Godot so I'll keep an eye on your future tutorials.
    Please do more! 👍

    • @FinePointCGI
      @FinePointCGI  10 หลายเดือนก่อน +2

      I will definitely be doing more! If you have any suggestions be sure to let me know or put them on my suggestions board!

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

    amazing tutorial! I am suprise I made it work on godot 3.5! i am so happy! you are the best!

  • @toshitosliba4737
    @toshitosliba4737 10 หลายเดือนก่อน +1

    I was following your video along and programming in C# xd managed to get the same results as you, which I really appreciate it

    • @playstuff5782
      @playstuff5782 9 หลายเดือนก่อน

      Any chance you can share the C#

  • @Phanom_Official
    @Phanom_Official ปีที่แล้ว +5

    Very good Tutorial I found out that you can also enter Is_action_pressed at Input then you can also do the mouvment in such a way that the left mouse button has to be held down so that you can move, very helpful :)

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

    Hello it was really grate. can you continue this as a series. I really liked it tnx so much

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

    Thank you kindly for your amazing help!

  • @zero_196
    @zero_196 7 หลายเดือนก่อน

    thank you for putting this together, super helpful!

  • @Luna_Kobold
    @Luna_Kobold ปีที่แล้ว +23

    there seems to be a crash if you click an area that has no objects in it? seems to be from position not existing. likely an easy fix but something to keep in mind!
    edit: was a super easy fix, just put this between print(result) and the navigationAgent.target_position lines:
    if result.size() < 1:
    return

    • @WalkerRileyMC
      @WalkerRileyMC ปีที่แล้ว +5

      result.is_empty() works as well

    • @vila4480
      @vila4480 10 หลายเดือนก่อน +1

      Thank you! Squashed a bug I didn't even notice was there!

    • @cucumbaboi2872
      @cucumbaboi2872 3 หลายเดือนก่อน

      thanks a lot

    • @Savage-tv4hs
      @Savage-tv4hs 2 หลายเดือนก่อน

      @@WalkerRileyMC Even simpler: `if result:`

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

      Thanks! Implemented the movement and came back a few weeks later to adress this bug.

  • @gabriel-xh8uo
    @gabriel-xh8uo ปีที่แล้ว

    TNX BRO BEST TUTORIAL

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

    nice video this kind of system reminds me of the rts games like age of empires, rise of nation etc...

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

    Yes, thank you!

  • @gim-ori
    @gim-ori ปีที่แล้ว

    awesome! thanks!

  • @TravisHouston-ri5cz
    @TravisHouston-ri5cz 6 หลายเดือนก่อน +2

    any chance we can get more on this? Like an actual character with walking animations? Maybe even a point and click combat system like runescape or diablo? great video and lvoe the way you explained this. Very much what I was looking for but cant find the next step video.

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

    Thank you very much

  • @fizzle1853
    @fizzle1853 10 หลายเดือนก่อน +3

    Hello there, it is a really good tutorial :D. Can you make a tutorial about rts selection with this?

    • @FinePointCGI
      @FinePointCGI  10 หลายเดือนก่อน +4

      I'll put it on my list.. I was talking to someone about making an RTS framework for Godot 4.

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

    Cool, you can use this for mini map movement. You just need to change the camera and projection.

  • @NebelunDev
    @NebelunDev 5 หลายเดือนก่อน +2

    I love this, how would you lerp the look_at though? I am trying to have a bit of initial moment and rotation as the character movement is quite jerky for the initial movement.

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

      In case you haven't solved this. This is what I found:
      Replace the content of the faceDirection method to: rotation.y=lerp_angle(rotation.y,atan2(-velocity.x,-velocity.z),.1)
      That's it! It works perfectly :)

  • @ReginaldSprinkhuizen
    @ReginaldSprinkhuizen 10 หลายเดือนก่อน +1

    Nice. Took me a while to find out that "set_target_location" has been changed into "set_target_position".
    Update: wow. I paused the video just before you have the same error. :-)

  • @iaminsanity2238
    @iaminsanity2238 7 หลายเดือนก่อน

    Good tutorial, getting a really inconsistent error about not being able to get the position of result because it's a dictionary though

  • @QqQq-bf8bd
    @QqQq-bf8bd ปีที่แล้ว +1

    i made 3d game in godot 3.5.1 and export apk, but not working in mobile. splash screen open and app has been stopped, 2d game working properly but 3d game not working in mobile (snapdragon, adreno) ,i will try single cube and camera but same result. please help what i do

  • @playstuff5782
    @playstuff5782 9 หลายเดือนก่อน

    Any chance of an updated version of this in C#?

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

    Finally, something useful on TH-cam for Godot.

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

    How on earth did you get the like buttons to do that at 28:30? (im on PC)

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

    Nice video! Would be nice if you included lerping during the faceDirection function.

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

      Your right I should have

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

      Here's how I did it:
      look_at(Vector3.FORWARD.rotated(Vector3.UP, rotation.y).lerp(direction, 0.1) + position)

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

    7:00 _ready runs when the node is in the tree and all its children are ready too
    this is important when you create nodes from the code
    create node, setup parameters of the node, add node to the tree, now onready vars are set and _ready function is called

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

    Hello ! i dont know if you did already , i think not. I would like a good video about level ! Savng level, loading level. Making big level. I did fallow a dozen a tutorial but everything i did is on a little plane :) . i tried to make level with algorithm and 3D tileset but it wasnt that great . That is my suggestion for a new video ! Thanks !

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

    I have an issue with the point of the PathFinder : whenever it is entering a new area of the navigationRegion (the one we bake), a new point is generated, thus forcing my character to stop and start again until reaching the final position. Any one met this issue aswell ?

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

    Makes me wonder if I should make some CRPG with this for a future game.
    Much appreciate the help and contribution, @FinePointCGI

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

    Is there any way to get the raycast to ignore the player and its model, so that you can click 'through' it? Stuck with this bit! Thank you for the video

    • @FinePointCGI
      @FinePointCGI  ปีที่แล้ว +5

      You can put them on different collision layers and only raycast that layer

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

    what should I do if the player goes to (0,0,0) after starting

  • @pour_understanding
    @pour_understanding 9 หลายเดือนก่อน

    can you make a click to move system using apply_force?

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

    what do you think unity engine can do this easier than this?

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

    I've done this verbatim 3 times and I haven't been able to get my CharacterBody3D to move, started it with new projects and updated the coding word for word and I get my rayQuery results back but my character just seems to refuse to move. I'm sure it's some newb issue I'm having but definitely frustrating!

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

      did you have the move and point on double tabs?

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

    Do you have a point and click version for 2D as well? I think I understand the basics but am having trouble understanding how the NavigationAgent2D works with more complex commands like attack and skill commands.

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

      I don't however I can make something for it what are you thinking?

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

      ​@@FinePointCGI I'm making an RTS combat system. I have unit selection down but I'm having trouble integrating the new navigation system when implementing skills [_move_to_target(), _attack_target(), _special_target()]
      With the premise being RTS systems have:
      controller = player
      pawn = "in game actor".
      and the intended outcome:
      if selected:/
      if controller.InputEvents(["right_click", "left_click", "special_attack", etc]):
      pawn.navigationagent.target_position = mouse_position
      pawn.statemachine = InputEvent
      pawn.enum.Command = InputEvent.animation.play()
      I hope that made sense.

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

      ​@@FinePointCGIit would be great if you make a 2d tutorial

    • @crimsonray4744
      @crimsonray4744 9 หลายเดือนก่อน +1

      I would also like a 2D tutorial, I’ve literally just started using godot

  • @mikael9931
    @mikael9931 8 วันที่ผ่านมา

    Everything else seems to work, but my character doesn't move. It only moves when i press my jump button that is located in func _physics_process(delta): . Does anyone know why this happens?

  • @sebastiaopinheiro4711
    @sebastiaopinheiro4711 8 หลายเดือนก่อน +1

    Hi! This is a pretty nice tutorial and worked perfectly.
    Do you have a video on how to make movement like league of legends? Pretty much camera follows you all the time on isometric 3D and the character looks instantly to the direction you started moving to... If not, could this be a video, please? XD

    • @nightmareTomek
      @nightmareTomek 8 หลายเดือนก่อน

      I think, you have to do these steps:
      1) set the camera node as a child of the CharacterBody instead of the world, then it will move with the character
      2) at 8:40 when he sets the mouse event with "is_action_just_pressed", you have to replace that with "is_action_pressed", I think that's what it's named. Anyway, a function that keeps triggering while you hold down your button. "just pressed" is only for one frame after pressing.
      Maybe 3) move it from the _input to the _process function, in case _input doesn't check every frame, then _process will.

    • @sebastiaopinheiro4711
      @sebastiaopinheiro4711 8 หลายเดือนก่อน +1

      @@nightmareTomek I can't believe this comment was only 2 weeks ago, I advanced so much in that time lol. But yeah, I got it some time ago using the 1) you meantioned, thanks.

    • @mast1665
      @mast1665 7 หลายเดือนก่อน +1

      @@nightmareTomek I just arrived at this point too. I want the camera to follow the player but dont change its rotation. When setting it as child of the player the camera keeps rotating with the player-object... Any clues on how to keep the camera in the starting angle like in Diablo?
      Worth mentioning is that I implemented movement by mouse via raycast I guess.

  • @Mrtargi
    @Mrtargi 7 หลายเดือนก่อน

    Hi! I have the problem with Invalid get index 'position' (on base: 'Dictionary'). When I try just to print a result everything works fine, but when I try to print result.position or move player, I have the error. I've checked the solution in the comments, but it didn't work. What can be the reason? TIA

    • @Mrtargi
      @Mrtargi 7 หลายเดือนก่อน

      Ok, I found the solution, here it is:
      nav_agent.target_position = result.get("position",ray_end)
      But now player moves without stop and in opposite direction

    • @Mrtargi
      @Mrtargi 7 หลายเดือนก่อน

      So, found this too. I am using camera rig, because I have isometric view and use couple camera's to make walls transparent. So, I can't use camera mount point that is over my player and it use Camera like in the middle of the map, so mouse click and as I tried to implement character turning over the mouse doesn't work for me properly(

  • @Gostyr
    @Gostyr 6 หลายเดือนก่อน

    i have this error:
    Cannot call method 'is_navigation_finished' on a null value.

    • @FinePointCGI
      @FinePointCGI  6 หลายเดือนก่อน

      That error means the object yoru calling is_navigation_finished on is null

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

    how would i attactch that camera to my player so it moves with the player

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

      found a solution ? :)

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

      You should be able to just drop the camera underneath the player and it will follow the player.

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

    I noticed the bug as you were writing it, thinking "that can't be right"... good tutorial nevertheless.

  • @henriquelc3
    @henriquelc3 8 หลายเดือนก่อน

    Ah, there's a problem with my godot, when I generate the script, several codes appear on the screen already written, and almost all the codes you write do not appear in my gdscript

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

    I followed the exact tutorial and it works BUT I get this error face_direction(): Node origin and target are in the same position, look_at() failed.

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

      OK, I did manage to fix it a little so I'm leaving this comment here in case anyone faces the same problem. The error has to do with the navigation agent path desired distance and target desired distance, 0.1 causes this error with me, changed their value to 0.5 still an error, changed it to 0.75 and the error is gone ! I'm not sure why, maybe a mouse sensitivity issue ?

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

      @@ahmed_mo2nis_productions I did a few test and the Player Y position also causes this. I put it a little higher and it fixed it.

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

    seems global_position.direction_to(targetPos) keeps shoving 0,-1,-0 into the variable.
    Frustrating as it worked fine in testing but soon as I moved the code to the prototype game this started up. No difference in anything other than it's a different game. targetPos is populated with the correct values...just seems when I try to do a direction_to it decides to set it to near the origin. Not 100% sure why one works and the other doesn't to be honest.

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

      Still no idea. Copy and pasted the entire code and it worked, but honestly absolutely nothing changed (and I checked...thrice).

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

      the cods isn't the only thing to check try making sure the nodes are all the same as well who knows could be one simple thing.
      @@WalkerRileyMC

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

    Seems like the player never reach the click position. It stops before it reach the mouse click position. But its velocity never stops. I realized when I added a character and try to play run animation, which never stops.

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

      That's interesting. I know there is a stop distance parameter in the navigation agent setting so that may help with your issue

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

      @@FinePointCGI Thanks for the reply and thanks for the video.

    • @AntonioRColon
      @AntonioRColon 6 หลายเดือนก่อน

      Is the Stopping Distance parameter still in Godot 4.2? I couldn't locate it.@@FinePointCGI

  • @shizukaryujoukai2465
    @shizukaryujoukai2465 5 หลายเดือนก่อน +2

    Any update to this? Its not working, im getting all of the data but its not moving.
    Edit: I fixed it

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

      How did you manage to fix it?

    • @dyja7
      @dyja7 3 หลายเดือนก่อน +1

      @@CocolandiaYT if you still need help, I had the same problem and it turned out the navigation region height of 0.01 was too low, I set it to 0.05 and it works now

    • @fooby7072
      @fooby7072 2 หลายเดือนก่อน +1

      @@CocolandiaYT I made it from scratch in the middle of the process and forgot to bake the navigation mesh again. So the mesh was tiny. I still got collision numbers but it just didn't navigate.

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

    I followed your code exactly, but for some reason it doesn't work at all. If I follow all the code up to printing out the result, it remains blank (even after updating the "project_ray_origin" to "project_ray_normal"
    if I change the print to "print(result.position)" then I get the error" Invalid get index 'position' (on base: Dictionary)" any ideas what this is all about?

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

      Result is a dictionary so print that and see what it comes back with. I wonder if they changed how it goes.

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

      @FinePointCGI I'm very new to godot (switching from Unity 😁) how do I print the dictionary?

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

      Just print(result)
      If your using c#
      GD.Print(result)

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

      @FinePointCGI oh! I did that before, and it's just blank. Which is very odd. Just gives me "{ }"

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

      What does your raycast look like? Currently it's not hitting anything

  • @user-ww6wl5sx7l
    @user-ww6wl5sx7l 9 หลายเดือนก่อน

    From 11:30 I feel like you are just reading out what you are typing and omitting the explanation.

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

    Hello brother, can you provide codes for godot 3.5.2?
    Godot 4 on linux has too many bugs. I can't even open the project 😭.

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

      What error are you getting? I may have someting like that allready made I think its called navigation in 3.5 i think?

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

      ​@@FinePointCGI Hi, can I ask for help in your discord server? I'm completely new to programming.

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

      Yeah it's open to anyone link is in the description

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

    Ok so A

  • @user-rf2wl7qj7u
    @user-rf2wl7qj7u 6 หลายเดือนก่อน +6

    wasted 5 hours because this video outdated, good shit dude

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

      Worked for me with 4.2.2

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

      When you say outdated do you mean the process no longer works or that there's a more efficient way to do it?
      Or is this a joke about how much Godot changes between releases?

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

    struggle to hard with the camera setup. really demotivating. developing feels so lonely and empty. like you are in the ocean struggling to survive on high waves while milions of people are around you and nobody is trying to help and when help comes it is a cement block on the feet xD googling since 2 hours how to fricking stop the nav agent player when he enters an area but apperently nobody on google tried to ever do that in godot xD

  • @ZeroCadence
    @ZeroCadence 9 หลายเดือนก่อน +1

    If you're stuck and your navigation agent is barely moving, switch the ray origin and ray normal piece of the code, and it should work. var from = camera.project_ray_origin(mouse_pos)
    var to = camera.project_ray_normal(mouse_pos) * ray_length - (from) , also Path Desired and Target Desired didn't work for me if I changed it from the default settings

    • @pliniomourao
      @pliniomourao 9 หลายเดือนก่อน

      That's what i was thinking. Using project_ray_origin for both only works if the camera position is using an offset of only one axis.

  • @QqQq-bf8bd
    @QqQq-bf8bd ปีที่แล้ว +1

    i made 3d game in godot 3.5.1 and export apk, but not working in mobile. splash screen open and app has been stopped, 2d game working properly but 3d game not working in mobile (snapdragon, adreno) ,i will try single cube and camera but same result. please help what i do

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

      It sounds like your phone doesn't support the 3d part of the engine what phone is it? You could try gles 2

    • @QqQq-bf8bd
      @QqQq-bf8bd ปีที่แล้ว +1

      @@FinePointCGI thanks for the reply and yeah morning i fixed the error to change gless2 render

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

      Hey I'm glad you fixed it!

    • @QqQq-bf8bd
      @QqQq-bf8bd ปีที่แล้ว +1

      @@FinePointCGI thanks