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
I watching this on 2024, there are even MORE changes in 4.3 version but this helped me a LOT to understand how to navigate throught documentation and make the needed fixes! thanks!
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
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! 👍
Thank you so much! I’m working on something very different (a 3d point and click) but I couldn’t get the ray casting working, this tutorial helped so much
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 :)
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. :-)
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.
This could be a nice little addition to the code: func face_direction(target_pos : Vector3, delta : float) -> void: var new_transform = transform.looking_at(target_pos, Vector3.UP) transform = transform.interpolate_with(new_transform, turn_speed * delta)
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.
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 :)
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
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
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.
@@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.
@@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.
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
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
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(
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!
I'm trying to make a game that controls like OldSchool RuneScape- most importantly, point-and-click walking along a grid of tiles. Is this possible to build off of this system?
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 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.
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
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 ?
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?
Because for some reason when you click, the result is empty. I do not understand why, but I see in forms the same code he uses. It is in "Ray-casting" and that chunk of code as an example is in _physics_process(delta) function I guess after update it is meant to be there now.
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.
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
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
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 ?
@@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
@@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.
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?
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.
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
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?
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
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
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
thank you dude
love u
I watching this on 2024, there are even MORE changes in 4.3 version but this helped me a LOT to understand how to navigate throught documentation and make the needed fixes!
thanks!
I really need to update this but I'm glad it worked for you!
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
result.is_empty() works as well
Thank you! Squashed a bug I didn't even notice was there!
thanks a lot
@@WalkerRileyMC Even simpler: `if result:`
Thanks! Implemented the movement and came back a few weeks later to adress this bug.
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! 👍
I will definitely be doing more! If you have any suggestions be sure to let me know or put them on my suggestions board!
Thank you so much! I’m working on something very different (a 3d point and click) but I couldn’t get the ray casting working, this tutorial helped so much
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 :)
I was following your video along and programming in C# xd managed to get the same results as you, which I really appreciate it
Any chance you can share the C#
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. :-)
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.
This could be a nice little addition to the code:
func face_direction(target_pos : Vector3, delta : float) -> void:
var new_transform = transform.looking_at(target_pos, Vector3.UP)
transform = transform.interpolate_with(new_transform, turn_speed * delta)
Hello there, it is a really good tutorial :D. Can you make a tutorial about rts selection with this?
I'll put it on my list.. I was talking to someone about making an RTS framework for Godot 4.
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.
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 :)
Hello it was really grate. can you continue this as a series. I really liked it tnx so much
amazing tutorial! I am suprise I made it work on godot 3.5! i am so happy! you are the best!
Cool, you can use this for mini map movement. You just need to change the camera and projection.
Nice video! Would be nice if you included lerping during the faceDirection function.
Your right I should have
Here's how I did it:
look_at(Vector3.FORWARD.rotated(Vector3.UP, rotation.y).lerp(direction, 0.1) + position)
THAAANKKK YOOOUUUU!!!
nice video this kind of system reminds me of the rts games like age of empires, rise of nation etc...
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
Thank you kindly for your amazing help!
TNX BRO BEST TUTORIAL
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
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.
@@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.
@@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.
Good tutorial, getting a really inconsistent error about not being able to get the position of result because it's a dictionary though
Yes, thank you!
How on earth did you get the like buttons to do that at 28:30? (im on PC)
awesome! thanks!
Thank you very much
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
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
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(
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!
what should I do if the player goes to (0,0,0) after starting
I'm trying to make a game that controls like OldSchool RuneScape- most importantly, point-and-click walking along a grid of tiles. Is this possible to build off of this system?
You can. It uses a very similar system in your navmesh you can choose the density of the mesh ant that would achieve this result
Any chance of an updated version of this in C#?
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.
I don't however I can make something for it what are you thinking?
@@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.
@@FinePointCGIit would be great if you make a 2d tutorial
I would also like a 2D tutorial, I’ve literally just started using godot
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
You can put them on different collision layers and only raycast that layer
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 ?
thank you for putting this together, super helpful!
I noticed the bug as you were writing it, thinking "that can't be right"... good tutorial nevertheless.
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?
Because for some reason when you click, the result is empty. I do not understand why, but I see in forms the same code he uses. It is in "Ray-casting" and that chunk of code as an example is in _physics_process(delta) function
I guess after update it is meant to be there now.
how would i attactch that camera to my player so it moves with the player
found a solution ? :)
You should be able to just drop the camera underneath the player and it will follow the player.
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.
That's interesting. I know there is a stop distance parameter in the navigation agent setting so that may help with your issue
@@FinePointCGI Thanks for the reply and thanks for the video.
Is the Stopping Distance parameter still in Godot 4.2? I couldn't locate it.@@FinePointCGI
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
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
It sounds like your phone doesn't support the 3d part of the engine what phone is it? You could try gles 2
@@FinePointCGI thanks for the reply and yeah morning i fixed the error to change gless2 render
Hey I'm glad you fixed it!
@@FinePointCGI thanks
can you make a click to move system using apply_force?
From 11:30 I feel like you are just reading out what you are typing and omitting the explanation.
i have this error:
Cannot call method 'is_navigation_finished' on a null value.
That error means the object yoru calling is_navigation_finished on is null
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.
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 ?
@@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.
what do you think unity engine can do this easier than this?
Any update to this? Its not working, im getting all of the data but its not moving.
Edit: I fixed it
How did you manage to fix it?
@@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
@@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.
Makes me wonder if I should make some CRPG with this for a future game.
Much appreciate the help and contribution, @FinePointCGI
"now, hopefully, if we click..." (crashes)
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?
Result is a dictionary so print that and see what it comes back with. I wonder if they changed how it goes.
@FinePointCGI I'm very new to godot (switching from Unity 😁) how do I print the dictionary?
Just print(result)
If your using c#
GD.Print(result)
@FinePointCGI oh! I did that before, and it's just blank. Which is very odd. Just gives me "{ }"
What does your raycast look like? Currently it's not hitting anything
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.
Still no idea. Copy and pasted the entire code and it worked, but honestly absolutely nothing changed (and I checked...thrice).
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
like and subscribe for this tysm bro
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
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.
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 😭.
What error are you getting? I may have someting like that allready made I think its called navigation in 3.5 i think?
@@FinePointCGI Hi, can I ask for help in your discord server? I'm completely new to programming.
Yeah it's open to anyone link is in the description
Ok so A
wasted 5 hours because this video outdated, good shit dude
Worked for me with 4.2.2
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?
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
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