Тёмный
No video :(

Simple FPS Enemy AI in Godot - Make an FPS in Godot Part 4 

Code with Tom
Подписаться 13 тыс.
Просмотров 33 тыс.
50% 1

Опубликовано:

 

24 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 194   
@CodeWithTom
@CodeWithTom 4 года назад
Important note! In this video I use the _process function, but ideally you should use the _physics_process function instead due to RayCast calls and movement.
@_mickmccarthy
@_mickmccarthy 4 года назад
@tompo1975 Bit late, but if you haven't found an answer yet you can give reference a script as a class using 'class_name `, other scripts can then inherit from that by using `extends ` at the top, much like a regular script will have `extends Node` or similar at the top. Hope that helps!
@spyd_d1983
@spyd_d1983 3 года назад
I just did this but my enemy keeps walking away from me
@CodeWithTom
@CodeWithTom 3 года назад
@@spyd_d1983 hey, sounds like you need to rotate your enemy 180 degrees
@spyd_d1983
@spyd_d1983 3 года назад
@@CodeWithTom no that doesn’t work it just goes backwards in the same direction no matter where I put it and when I rotate it it just goes forward in the same direction
@CookieMagician
@CookieMagician 4 года назад
bruh literally watched the first three episodes yesterday and was sad there was no episode 4. Thanks!
@CodeWithTom
@CodeWithTom 4 года назад
Thanks for watching, hope you enjoyed part 4 😁
@MrAndrjuha
@MrAndrjuha 4 года назад
@@CodeWithTom We will enjoy if these episodes continues:-)
@explosivesexplode
@explosivesexplode 3 года назад
If you're having issues with "Invalid get index 'collider' (on base: 'Dictionary'). Add if not result.empty(): before if result.collider.is_in_group("player"): My code looks like this: if target: var result = space_state.intersect_ray(global_transform.origin, target.global_transform.origin) if not result.empty(): if result["collider"].is_in_group("Player"): Thanks to the people in the Godot discord for helping me out.
@chrislenz
@chrislenz 2 года назад
Thanks! This is exactly what I was having issues with.
@rachidazekaoui4306
@rachidazekaoui4306 Год назад
Wow thanks!
@seannesler
@seannesler 4 года назад
Thank you! This helped so much! I am trying to get back into game design after years, totally new to Godot, and this helped a LOT. Just a couple bugs I am sure there are easy fixes for that I just can't figure out. 1) I added two AIs to a scene and both turn red when one sees the player character. 2) If the player character is standing on an elevated surface, the AI will turn until it is practically horizontal to look at the player. The AI used to literally fly to reach the player if the player was elevated, but I fixed that easily (watched the gravity tutorial you made and that kept them from flying).
@larsthedude1984
@larsthedude1984 2 года назад
This is EXACTLY what I needed for my stealth game. Thank you!!
@ryoneer
@ryoneer 3 года назад
FOR ANYONE WITH THE GET INDEX COLLIDER ERROR!!!: Check and see where the origin of the player and the enemy nodes are. In my case they were at y= 0 and the floor level was also at y=0 which means the raycast is in the floor, thus cant reach the player, if anything for that matter. I fixed it by placing a spatial node on both the player and on the enemy at about half the body height and raycasting from there.
@AsimFojiOfficial
@AsimFojiOfficial Год назад
wait can u explain. I dont understand. I am getting this error though
@sandakureva
@sandakureva 2 года назад
I originally found your channel because I was stuck on a specific problem for a specific game jam... but I've decided to stick around because all of the content is pretty good.
@abdulbasitado6180
@abdulbasitado6180 4 года назад
It's good to have you back Tom. I was basically heartbroken when the videos stopped coming.. Thank you.
@CodeWithTom
@CodeWithTom 4 года назад
Thanks it's great to be back! 😁
@jowilson5581
@jowilson5581 4 года назад
This is fantastic. With these four videos, I have a nice framework in place to make my own game idea! Thanks so much for the leg up.
@CodeWithTom
@CodeWithTom 4 года назад
You're very welcome Jo. I'm planning to refine these lessons and extend them into a full fledged course at some point. I'm also toying with the idea of releasing an open source first person framework
@jowilson5581
@jowilson5581 4 года назад
@@CodeWithTom fwiw I think releasing the core functionality as a plug-in framework would be a nice gesture, very much in the spirit of Godot. I'm actually making some changes to what we've done so far, as the game I have in mind is a stealth game where the player has a slingshot as opposed to a hitscan weapon. But! Just having core stuff like movement keys, mouse look, interactable objects, and a basic raycast in place demonstrating layers and groups, it all makes for a nice base on which to build.
@CodeWithTom
@CodeWithTom 4 года назад
@@jowilson5581 absolutely! The Ludum Dare entry I made uses projectile bullets instead of hitscan so id probably add that in too. Although it's a little buggy right now which I believe is to do with the speed of the bullet and the rate at which the collision area node reports bodies entering it. Will need to figure out the issue first. Also thinking of adding in things like customizable head bobbing, sway, camera shakes etc.
@justinwaluigi5485
@justinwaluigi5485 3 года назад
The enemy targeting the player doesn't work. Seems like look_at might be changed or removed from this version.
@giantenemycrab5596
@giantenemycrab5596 Год назад
Does the enemy have a problem where it points at the player but there orientation is wrong (e.g face down) and it won't track the player? I might have a fix, otherwise, no idea
@vickylance
@vickylance 4 года назад
I really hope that you continue these tutorials you have got a knack to make these tutorials really enjoyable
@CodeWithTom
@CodeWithTom 4 года назад
Thank you Vignesh, there are plenty more to come.
@AceSpectre
@AceSpectre 4 года назад
Thanks for continuing this series, i was using it to guide me through 3d in Godot and noticed that it cut off at part 3. Youve definitely made my quarantine project easier!
@CodeWithTom
@CodeWithTom 4 года назад
Glad to hear it! :D
@juiceman7649
@juiceman7649 3 года назад
Was about to subscribe until I realised it's Code with Tom no surprises there best Godot tutorials on youtube, making my beginner coding journey possible.
@bobojenkins5805
@bobojenkins5805 3 месяца назад
12:04 is what you clicked for
@ratrodshaggy4840
@ratrodshaggy4840 4 года назад
Absolutely awesome tutorials. It’s perfect for someone with attention span issues. Fast, efficient and to the point. I’ve watched other tutorial videos that give the same amount of instruction, but the video is over an hour long because they keep going off on tangents. Drives me nuts. Anyway, I’ve subscribed and can’t wait for more videos. Are you gonna do any about how to do build a scene with textures and objects. I have no idea how all that works. Thanks again.
@CodeWithTom
@CodeWithTom 4 года назад
Thank you so much for the kind words Ratrod. Glad you find these tutorials useful and concise 😁
@frankoesavage8314
@frankoesavage8314 4 года назад
Yeah hes right, I can listen and know whats going on while not even watching the video, Voice is perfect. I like how he isnt overly funny neither, but if you pay attention closely there some funny jokes in there somewhere lol
@mikebrolo
@mikebrolo 4 года назад
Been waiting for a while!!
@CodeWithTom
@CodeWithTom 4 года назад
Apologies for the wait! haha
@grassly7997
@grassly7997 3 года назад
im having a problem at 13:25, for some reason when the enemy sees me they turn the opposite way of me. Every time i go into their FOV they just turn by 180°
@LeKooKoo
@LeKooKoo 3 года назад
I had the same issue but I fixed it by rotating the Enemies Area the other way.
@Allen-cx6yi
@Allen-cx6yi 3 года назад
I have the same problem I tried rotating the area and nothing happened pls help
@mahyuddinchan3012
@mahyuddinchan3012 3 года назад
@@Allen-cx6yi I changed the collisionPolygon node to -90 degrees in transform and changed the area node to 90 degrees in trasform. hopes this helps!
@naraz927
@naraz927 3 года назад
@@mahyuddinchan3012 thanks it helped a lot!
@lionlight9514
@lionlight9514 2 года назад
@@mahyuddinchan3012 Wait on which axis was the x y or z?
@Nyterian
@Nyterian 4 года назад
Please continoue this series
@CodeWithTom
@CodeWithTom 4 года назад
Absolutely 😁👌
@joyeldsilva
@joyeldsilva 2 года назад
Can you do a tutorial on enemy shooting bullets?
@monkeyballs188
@monkeyballs188 4 года назад
instead of passing different functions for the color changing, you can make one function and pass arguments for the colors instead
@tridra5714
@tridra5714 4 года назад
Been waiting for this. So glad its finally here
@CodeWithTom
@CodeWithTom 4 года назад
Glad you're here to watch it! :)
@masterox2
@masterox2 4 года назад
I really like your tutorials
@CodeWithTom
@CodeWithTom 4 года назад
Thank you Shadow! 😁
@panskibinski
@panskibinski 3 года назад
The issue with enemy clones turning red/green together is that they share the same spatial material instance. The solution is to create new one for each of them at the creation or update
@spooky130u
@spooky130u 4 года назад
I love the way you do the tutorials---describing everything in detail as you add it, and then doing a full recap at the end. Fantastic....makes it much easier for someone who, during his first cancer, had 3 brain tumors, three very severe brain surgeries, whole-brain/max-dose radiation therapy, plus very severe chemo which does cross the barrier into the brain, to learn from. Btw, minor point: are there supposed to be two part 4s? :-)
@CodeWithTom
@CodeWithTom 4 года назад
Hi Jim, thank you so much for the feedback. I'm really glad you find my method of teaching useful. It sounds like you've gone through an awful lot, but it fills me with joy to hear that my videos are helping you to learn game development and I wish you every success in your journey! 😁👍
@spooky130u
@spooky130u 4 года назад
Is there supposed to be a part 5? The title and video for four and five are the same. Just wondering. Don't want to miss the end of this tutorial set! :-) In part four (the actual part four not part four that's #5), you mention that the new setting is for something you'll be adding later. I gather, since it really wasn't used in part four, that there is a missing part five. But I could be mistaken. Oh, and the zip with the code is also labelled part 4. As for going through a lot, yes, definitely. But I put cancer #1 through hell. Every time it tried to kill me, the only thing it accomplished was to make me more furious with it and that much more defiant towards it. We caught cancer #2 so early it was just one surgery and done. And we caught #3 before it even became #3 (pre-cancerous mass). My email signatures read: The score: Me: 2 + 1-ish Cancer: 0The really bad thing is that #1 forcibly retired me and dumped me into Social So-Called Security Disability. Gamedev is my latest attempt at (eventually) making enough money to escape from this financial hell.
@CodeWithTom
@CodeWithTom 4 года назад
Hey Jim, good spot! There are only 4 parts, looks like I mistakenly added part 4 to the playlist twice. Part 5 will be coming soon 😁
@spooky130u
@spooky130u 4 года назад
@@CodeWithTom Looking forward to it.
@infelicitas
@infelicitas 4 года назад
Awesome! thanks man
@CodeWithTom
@CodeWithTom 4 года назад
You're very welcome :)
@ashkantofangdar6591
@ashkantofangdar6591 4 года назад
Fantastic i am surprised that these videos have so much low like, but keep up the good work. from the last three episodes i can even create my idea that i had struggled with in past 5 month.
@CodeWithTom
@CodeWithTom 4 года назад
That's amazing Ashkan, happy I could help!
@BogdanKustan
@BogdanKustan 4 года назад
Nice content, only some comments: 1. Why not use _physics_process instead of _process? All physics stuff must be handled in _physics_process(): move_and_slide -- This method should be used in Node._physics_process (or in a method called by Node._physics_process), as it uses the physics step’s delta value automatically in calculations. Otherwise, the simulation will run at an incorrect speed. 2. move_and_slide() doesn't need multiplication by delta: move_and_slide -- Unlike in move_and_collide, you should not multiply it by delta - the physics engine handles applying the velocity. 3. Why not to give each entity a class_name and then check it using "colider is Player" instead of using groups?
@CodeWithTom
@CodeWithTom 4 года назад
Hey Bogdan, you're absolutely right! It's been a few months since I've touched Godot and I'm a little rusty as you can tell 😂 All of your points are 100% valid and I appreciate you pointing them out. I like your type checking solution rather than checking the groups too! Thanks for the constructive comments. 😁👌
@efimov90
@efimov90 4 года назад
Enemy feels like dalek. It was really scary after i add tracking code. It was fun.
@CodeWithTom
@CodeWithTom 4 года назад
Glad you enjoyed it :)
@frankoesavage8314
@frankoesavage8314 4 года назад
very exciting videos, Brings me back to the learning days of Unity3d for sure! Bringing back the best, thank you
@CodeWithTom
@CodeWithTom 4 года назад
Thank you Frankoe I really appreciate it :)
@amirghalbarband3038
@amirghalbarband3038 2 года назад
Thank you so much man, your tutorial is really helpful
@_mickmccarthy
@_mickmccarthy 4 года назад
To those having the "Invalid get index 'collider' (on base: 'Dictionary')" error, it does (to me at least) seem to be an OSX-specific issue. Unfortunately this isn't the first time I've had OSX-specific issues with Godot. I'm now running the project on Linux and of course Tom (and many others I assume) are running it on Windows with no issues.
@Bananeisafree
@Bananeisafree 4 года назад
Pretty darn good tutorial series !
@CodeWithTom
@CodeWithTom 4 года назад
Glad you like them! Thank you!
@ThatGatorGuyTGG
@ThatGatorGuyTGG 2 года назад
Hello, for those whom are having the albedo problem "attempted to call function 'albedo_color' in base 'null instance'" when running the get_surface_material. The only solution around it with the same architecture of code is to use get_active_material instead. At least for Godot version 3.4.4. My 'guess' to why get_surface_material doesn't work is that it only returns the material for the surface of the mesh and that material is something different than the material used for drawing the mesh? Godot says that it is null which means it hasn't been assigned anything. When using get_active_material it returns the correct material. This is just my ignorant guess lol. No idea why it works for some and doesn't for others? If it helps I am on Linux, Arch 5.18.3, LLVM 13.0.1, and Godot 3.4.4.
@mackenzienewton4829
@mackenzienewton4829 Год назад
thank you so much i pulling my hair out on this one😅
@smutnywalen
@smutnywalen 4 года назад
Nice and simple video. Good work!
@CodeWithTom
@CodeWithTom 4 года назад
Thank you! Cheers!
@pascalcasier959
@pascalcasier959 4 года назад
Thank you for another great tutorial.
@truthtoons8833
@truthtoons8833 Год назад
Thank you!
@Icie145
@Icie145 3 года назад
so instead of the enemy looking at me, he looks in opposite direction, I follow the same code as you did edit: The rotation works, but how do i lock the y rotation?
@spyd_d1983
@spyd_d1983 3 года назад
Mine did the same thing and all I was move the nose to the other side and rotate the area by 180 degrees
@plurakok
@plurakok 3 года назад
Same problem here
@yurimednikov304
@yurimednikov304 3 года назад
@@spyd_d1983 That worked for me! Thanks!
@sabinekine2737
@sabinekine2737 3 года назад
King Dunnad 8 months ago This happens because your enemy turns the wrong way, and then the player is out of the enemy's line of sight. To fix this: (You don't have to set the translation to be exactly the same as I have, roughly the same should work) Go to Enemy scene. Click on the MeshInstance node (the capsule). Go to the Inspector tab and click to expand Transform. Translation should be all 0. Set Rotation Degrees to x: 90, y: -180, z: 0. Scale is fine as it is. Click on the MeshInstance2 node (the cube to point where it's going). Go to the Inspector tab and click to expand Transform. Set Translation to x: 0, y: 0.7, z: -0.8. Set Rotation Degrees to x: 0 y: 0, z: 0. Scale is fine as it is. Click on the CollisionShape node (to collide with the enemy). Go to the Inspector tab and click to expand Transform. Set Translation to x: 0, y: 0, z: 0. Set Rotation Degrees to x: 90, y: 0, z: 0. Scale should be all 1. Click on the Area node (the field of view). Go to the Inspector tab and click to expand Transform. Set Translation to x: 0, y: 0, z: -1.063. Set Rotation Degrees to x: 0, y: 90, z: 0. Scale should be all 1. Click on the CollisionPolygon node (the field of view collision area). Go to the Inspector tab and click to expand Transform. Translation should be all 0. Set Rotation Degrees to x: 90, y: 0, z: 0. Hopefully that helps.
@FarmMyCrops
@FarmMyCrops 3 года назад
@@sabinekine2737 worked for me thanks so much
@tubagusthariqgilbraltar7499
@tubagusthariqgilbraltar7499 4 года назад
What is state machine use for???
@bronxzoo8344
@bronxzoo8344 2 года назад
I AM JUST GETTING STARTED IN THIS, SO I LOOK FOR HELP , AND IN THIS VIDEO, THE ONLY THING THAT IS WORKING FOR ME IS THE COLOR AND THE PART THE ENEMY IS LOOKING AT ME, NOTHING ELSE WORKS. ANY ANSWERS / TOM.
@jlewwis1995
@jlewwis1995 4 года назад
How computationally expensive is directspacestate? Wouldn't it be more optimized to have a raycast node that only gets enabled when a non-world object enters the viewing area? I could see grabbing the whole world stare getting *really* bad in terms of cpu and ram use if you have a large map with lots of enemies
@CodeWithTom
@CodeWithTom 4 года назад
Good question. I've not ran any benchmarks but I believe it is extremely cheap to run raycasts in this way. Especially since we only grab a reference to the space state object once (during the _ready call). It's main purpose is to make physics queries like we're doing here. docs.godotengine.org/en/3.2/classes/class_physicsdirectspacestate.html
@CodeWithTom
@CodeWithTom 4 года назад
Note, you may want to modify the code slightly to call this inside the _physics_process instead for thread safety.
@aetheriet9363
@aetheriet9363 3 года назад
Don't expect you to respond but could you do a video on adding gravity and jumping to the enemies AI
@bobojenkins5805
@bobojenkins5805 3 месяца назад
nobody has enough balls to code a logic for projectile enemies. you made a capsule follow the player thats cool i guess
@mrmixedvideomaker9767
@mrmixedvideomaker9767 4 года назад
Nice video, but when I entered the enemy's field of view, it turns away, making it green. please help.
@CodeWithTom
@CodeWithTom 4 года назад
Sounds like you may need to rotate your enemy mesh by 180 degrees on the Y axis.
@thilosaur2169
@thilosaur2169 3 года назад
Had the same problem, fixed now
@lukepire
@lukepire 2 года назад
Whn i play my game the enemy just goes to 0,0,0 and when i wal in fron of the enemy it doesnt pick up in the output box
@cosmicfruit7111
@cosmicfruit7111 2 года назад
How would you apply gravity to the enemy?
@kushagrajain5681
@kushagrajain5681 2 года назад
i always got "Invalid get index 'collider' (on base: 'Dictionary')" error when in i jump in enemy radar
@supremeasura3358
@supremeasura3358 3 года назад
these capsules looking hella sus ngl
@shire7949
@shire7949 4 года назад
Cool as always! thanks.
@CodeWithTom
@CodeWithTom 4 года назад
Thank you too!
@atharvvbhandare
@atharvvbhandare 3 года назад
Thanks sir plz make a video to add sound effects and particles
@The10ie
@The10ie 3 года назад
how did you get the crosshair
@bulaxa2900
@bulaxa2900 4 года назад
Instead of making groups you could just use the collision layers inside of the engine in the inspector, in the game i'm currently working on instead of using the groups i used layers, and it's quite the same thing but I prefer the layers method
@CodeWithTom
@CodeWithTom 4 года назад
Yep that's another option too 😁
@AleksandarPopovic
@AleksandarPopovic 4 года назад
Good jobe, and good luck with, your projects!!
@CodeWithTom
@CodeWithTom 4 года назад
Cheers Aleksander
@RobiworksLt
@RobiworksLt Год назад
Thank you,
@kingzeeb319
@kingzeeb319 4 года назад
Awesome series, thanks a lot! I'm trying to apply this to a Doom Clone, it's all good except there aren't many tutorials on Doom-like billboards with directional sprites in a 3D environment.
@CodeWithTom
@CodeWithTom 4 года назад
Interesting idea, I'll add it to my list of topics 😁
@strum007
@strum007 4 года назад
Miziziziz has a video on that
@ouhellouder9269
@ouhellouder9269 2 года назад
i actualy followed this tutorial and in part when enemy doesnt see us behind the wall dont work every time i go away from wall he can see me and chase me
@thegamebums6791
@thegamebums6791 4 года назад
can the next episode be another episode on the enemy AI system? The one that I am currently using isn't working for the game I'm busy making. I am just asking if it can be in the next episode, thanks. Great tutorials btw!
@liemaeu
@liemaeu 4 года назад
I get the error: invalid get index 'collider' (on base: Dictionary) at the line if result.collider.is_in_group("Player"):
@_mickmccarthy
@_mickmccarthy 4 года назад
@deadninja Did this work for you? As collider isn't a function, so I can't see how it would. I added a check for the presence of a collider property and it seems that the result does not have one. Also added a breakpoint and inspected it and there is no collider property.
@_mickmccarthy
@_mickmccarthy 4 года назад
@deadninja Odd! What version of Godot are you running if you don't mind me asking? Might be a small difference between versions or something. There seems to be both a lot of people where this tutorial works fine and a lot who are having this particular issue. Very strange!
@_mickmccarthy
@_mickmccarthy 4 года назад
@deadninja Looks like it's an OSX problem, started the tutorial on OSX. Moved across to Linux once I couldn't find a simple solution and everything worked fine. Pulled the changes back to OSX to verify it was OSX and it crashed again when spotted by an enemy.
@gdmattartz3071
@gdmattartz3071 4 года назад
sometimes im having an error called Invalid get index 'collider' (on base: 'Dictionary'). how can i fix this?
@ryoneer
@ryoneer 3 года назад
found a fix yet?
@ryoneer
@ryoneer 3 года назад
found a fix. look at recent comment from me its the origins of enemy and player messing up the raycast
@pedroluzio
@pedroluzio Год назад
For some weird reason my Enemy is upset with my Player... everytime I enter his field of view he turns 180 degrees the oposite side :( lol
@invaderHUNK
@invaderHUNK Год назад
Have you tried apologizing?
@fragarena9910
@fragarena9910 4 года назад
love your tuts
@CodeWithTom
@CodeWithTom 4 года назад
Thank you 😊
@fragarena9910
@fragarena9910 4 года назад
@@CodeWithTom yeah , it's been quite a while since your last fps tut 😄
@larrybird3729
@larrybird3729 4 года назад
btw how would you make the enemy look at the target slower? instead of instant? Thanks
@CodeWithTom
@CodeWithTom 4 года назад
Hi Larry, you would need to use linear interpolation. I will do a video on this topic in the future.
@ohmyshell
@ohmyshell 4 года назад
where are the object shadows? it looks so flat. Cant wait for the rest of the series. Hope you cover post processing and graphics.
@CodeWithTom
@CodeWithTom 4 года назад
Heh, yes I'll cover this in a future tutorial
@tiinaposkiparta9880
@tiinaposkiparta9880 4 года назад
Amazing and interesting!!! 🙋😁
@CodeWithTom
@CodeWithTom 4 года назад
Thanks Tiina 😁
@tiinaposkiparta9880
@tiinaposkiparta9880 4 года назад
@@CodeWithTom You're very welcome 😁
@blacksaturdayrecords3212
@blacksaturdayrecords3212 3 года назад
when i make rooms and i look past a certain distance, the background clips with the WorldEnvironment node. How do I fix this?
@PabloMartinez-qf4yr
@PabloMartinez-qf4yr 4 года назад
Awesome!
@CodeWithTom
@CodeWithTom 4 года назад
Thanks Pablo!
@Shortclipsyt9
@Shortclipsyt9 4 года назад
pls part 5 of make an FPS Game :)
@CodeWithTom
@CodeWithTom 4 года назад
I will, but it might be a while. I have a lot of things I'd love to cover :) I'm actually considering re-doing the series as a full course.
@unworthy.potato
@unworthy.potato 3 года назад
11:44
@BirdaoGwraBasumatary
@BirdaoGwraBasumatary 3 года назад
Please make how to change weapon.
@andi8489
@andi8489 4 года назад
Thank you very much! Your tutorials are the best. I try to make a simple fps engine with some modern features like camera shake when shooting or blood overlays splat to walls when enemies are hit. Could you include something like that? A sprite weapon and sprite enemy would be nice too. I aim to have 4 directional sprite enemies. Aaand are trigger areas possible? Lets say the player walks into an area, the light goes out and a sound plays.
@CodeWithTom
@CodeWithTom 4 года назад
Great suggestions, I'll definitely add them to my list of topics to cover!
@jlewwis1995
@jlewwis1995 4 года назад
It seems like it would be better to create a more cone shaped trapezoid for the viewing area rather than a completely flat one, can you do that with the collision polygon?
@CodeWithTom
@CodeWithTom 4 года назад
Hey James, very good point. The CollisionPolygon, from what I can tell, has a set height. You may want to opt for a CollisionShape to do something more like a cone. Or simply use a Sphere and check the angle to the player to see if it falls within your desired FoV. But good point! :)
@joshuapasco9026
@joshuapasco9026 4 года назад
I'm not sure why.. But when I enter the Area, it prints myself as "Player entered" just fine, but when I put if body.is_in_group("Player"): it doesn't detect or print anymore. Have I somehow changed my group? But exiting still prints, just not entering. Thank you. func _on_Sight_body_entered(body): if body.is_in_group(Player): print(body.name+" entered") func _on_Sight_body_exited(body): print(body.name+" exited")
@youzzaim4010
@youzzaim4010 2 года назад
anybody elses enemy going to 0, 0, 0 instead of the play @Code with Tom. pls help
@pravinvjreigns6055
@pravinvjreigns6055 Год назад
My enemy looks opposite to the player,please put video about it
@simplesten3450
@simplesten3450 Год назад
Had the same issue. I fixed it because the AI was built “backwards” try moving the face to the other side of the AI. Hope that helps!
@cringedmossy5260
@cringedmossy5260 4 года назад
hi :emojy:smile
@abbaszangaraky5693
@abbaszangaraky5693 3 года назад
Hi Can I use this tutorial in my project? Not problem?
@mldsh
@mldsh 4 года назад
Hello Tom! Can you help me with my problem please? Debugger: "Invalid get index 'collider' (on base: 'Dictionary'). It's happening when I exiting Area. I don't know what to do
@vickylance
@vickylance 4 года назад
Rewatch the tutorial and see carefully see which part you missed.
@thilosaur2169
@thilosaur2169 3 года назад
My enemy runs away instead of coming towards me. How can i fix this?
@sabinekine2737
@sabinekine2737 3 года назад
Try this: King Dunnad 8 months ago This happens because your enemy turns the wrong way, and then the player is out of the enemy's line of sight. To fix this: (You don't have to set the translation to be exactly the same as I have, roughly the same should work) Go to Enemy scene. Click on the MeshInstance node (the capsule). Go to the Inspector tab and click to expand Transform. Translation should be all 0. Set Rotation Degrees to x: 90, y: -180, z: 0. Scale is fine as it is. Click on the MeshInstance2 node (the cube to point where it's going). Go to the Inspector tab and click to expand Transform. Set Translation to x: 0, y: 0.7, z: -0.8. Set Rotation Degrees to x: 0 y: 0, z: 0. Scale is fine as it is. Click on the CollisionShape node (to collide with the enemy). Go to the Inspector tab and click to expand Transform. Set Translation to x: 0, y: 0, z: 0. Set Rotation Degrees to x: 90, y: 0, z: 0. Scale should be all 1. Click on the Area node (the field of view). Go to the Inspector tab and click to expand Transform. Set Translation to x: 0, y: 0, z: -1.063. Set Rotation Degrees to x: 0, y: 90, z: 0. Scale should be all 1. Click on the CollisionPolygon node (the field of view collision area). Go to the Inspector tab and click to expand Transform. Translation should be all 0. Set Rotation Degrees to x: 90, y: 0, z: 0. Hopefully that helps.
@tr3xmusic852
@tr3xmusic852 3 года назад
Bruh my enemy looks away when Im in front of him, help
@immanuelc885
@immanuelc885 3 года назад
same
@hrithikjoshi6918
@hrithikjoshi6918 3 года назад
same, did you find a fix?
@sabinekine2737
@sabinekine2737 3 года назад
King Dunnad 8 months ago This happens because your enemy turns the wrong way, and then the player is out of the enemy's line of sight. To fix this: (You don't have to set the translation to be exactly the same as I have, roughly the same should work) Go to Enemy scene. Click on the MeshInstance node (the capsule). Go to the Inspector tab and click to expand Transform. Translation should be all 0. Set Rotation Degrees to x: 90, y: -180, z: 0. Scale is fine as it is. Click on the MeshInstance2 node (the cube to point where it's going). Go to the Inspector tab and click to expand Transform. Set Translation to x: 0, y: 0.7, z: -0.8. Set Rotation Degrees to x: 0 y: 0, z: 0. Scale is fine as it is. Click on the CollisionShape node (to collide with the enemy). Go to the Inspector tab and click to expand Transform. Set Translation to x: 0, y: 0, z: 0. Set Rotation Degrees to x: 90, y: 0, z: 0. Scale should be all 1. Click on the Area node (the field of view). Go to the Inspector tab and click to expand Transform. Set Translation to x: 0, y: 0, z: -1.063. Set Rotation Degrees to x: 0, y: 90, z: 0. Scale should be all 1. Click on the CollisionPolygon node (the field of view collision area). Go to the Inspector tab and click to expand Transform. Translation should be all 0. Set Rotation Degrees to x: 90, y: 0, z: 0. Hopefully that helps.
@hshsjsjsj506
@hshsjsjsj506 4 года назад
look_at(target.global_transform.origin, Vector3.UP) at this line why my enemy is looking in opposite direction its not following my player . please help me hahah
@nightRobinO_O
@nightRobinO_O 4 года назад
In Godot 3D, the front is the negative Z axis. Rotate your enemy first to face the -Z axis
@thedevine3756
@thedevine3756 4 года назад
Is it possible to add building mechanics?
@CodeWithTom
@CodeWithTom 4 года назад
I was actually just thinking about this... So possibly in the future 😁
@ishkapoor7931
@ishkapoor7931 4 года назад
totally loved your tutorial... part-4 is really amazing... but I ran into a problem... kindly help!!! in the enemy script|func _on_Area_body_entered(body)|.... there is an error that popped up "Attempt to call function 'Albedo_color' in base 'null instance' on a null instance". please help! I want my game to work properly... the game crashes whenever I come across the enemy.
@CodeWithTom
@CodeWithTom 4 года назад
Hey Ish, thank you! Looks like you're trying to call a function called "Albedo_color". It should be "set_albedo". Give that a go and let me know if that fixes it. Also feel free to join the discord if you need further assistance 😁
@ishkapoor7931
@ishkapoor7931 4 года назад
@@CodeWithTom well I used |func set_color_red(): $MeshInstance.get_surface_material(0).set_albedo(Color(1,0,0)) | as the function and |set_color_red()| to call the function.... but every time I run this... |Attempt to call function 'set_albedo' in base 'null instance' on a nullinstance.|
@VahitCanEmen
@VahitCanEmen 2 года назад
I wrote the code, but she avoids me as if she is offended by my character.
@magma0473
@magma0473 4 года назад
Enemy looks away for some odd reason? Please help
@nightRobinO_O
@nightRobinO_O 4 года назад
In Godot 3D, the front is the negative Z axis. Rotate your enemy first to face the -Z axis
@sabinekine2737
@sabinekine2737 3 года назад
King Dunnad 8 months ago This happens because your enemy turns the wrong way, and then the player is out of the enemy's line of sight. To fix this: (You don't have to set the translation to be exactly the same as I have, roughly the same should work) Go to Enemy scene. Click on the MeshInstance node (the capsule). Go to the Inspector tab and click to expand Transform. Translation should be all 0. Set Rotation Degrees to x: 90, y: -180, z: 0. Scale is fine as it is. Click on the MeshInstance2 node (the cube to point where it's going). Go to the Inspector tab and click to expand Transform. Set Translation to x: 0, y: 0.7, z: -0.8. Set Rotation Degrees to x: 0 y: 0, z: 0. Scale is fine as it is. Click on the CollisionShape node (to collide with the enemy). Go to the Inspector tab and click to expand Transform. Set Translation to x: 0, y: 0, z: 0. Set Rotation Degrees to x: 90, y: 0, z: 0. Scale should be all 1. Click on the Area node (the field of view). Go to the Inspector tab and click to expand Transform. Set Translation to x: 0, y: 0, z: -1.063. Set Rotation Degrees to x: 0, y: 90, z: 0. Scale should be all 1. Click on the CollisionPolygon node (the field of view collision area). Go to the Inspector tab and click to expand Transform. Translation should be all 0. Set Rotation Degrees to x: 90, y: 0, z: 0. Hopefully that helps.
@Shortclipsyt9
@Shortclipsyt9 4 года назад
how can i make that the enemy kills me / attack
@CodeWithTom
@CodeWithTom 4 года назад
I have it on my list of topics to cover :)
@Shortclipsyt9
@Shortclipsyt9 4 года назад
@@CodeWithTom that would be amazing :)
@Shortclipsyt9
@Shortclipsyt9 4 года назад
@@CodeWithTom and another question, is there any way to make win the game after collecting for example 5 coins or something ? :)
@jamesxxxyz8775
@jamesxxxyz8775 4 года назад
Enemy look too fast to the player. How can you do this smooth? 13:48
@CodeWithTom
@CodeWithTom 4 года назад
Valid point, this was mostly for demonstration purposes. But you can achieve this by using linear interpolation between the enemy's current direction and the direction to the player. I will cover this in another tutorial in the future.
@BogdanKustan
@BogdanKustan 4 года назад
I am doing something like this in _process(): var needed_angle = get_angle_to(player.global_position) rotation = lerp_angle(rotation, needed_angle, delta)
@CodeWithTom
@CodeWithTom 4 года назад
@@BogdanKustan Great solution 😁
@davidheadley8589
@davidheadley8589 3 года назад
@@BogdanKustan it says get_angle_to isn’t declared in current class. I’m sure I’m just messing up somehow
@bigbird612
@bigbird612 4 года назад
where is the github link?
@CodeWithTom
@CodeWithTom 4 года назад
Hi Nucleas, it's in the description.
@bigbird612
@bigbird612 4 года назад
@@CodeWithTom thanks for some reason it wasnt showing me them
@ya_boi_logs9792
@ya_boi_logs9792 3 года назад
Hey, I just finished coding the part of the tutorial which is debugged at 13:48 and I can't seem to get it working. Before I started this step it was working fine (The change color when in line of sight part). But now when I add in the 'following the player' step, the enemy just sits there and doesn't move, change colors, or anything else. There also isn't an error popping up in the engine after I have tried the debug. Thanks for the help!
@jenilamansalapus8636
@jenilamansalapus8636 3 года назад
did you add the player to group?
@ranjunewar3776
@ranjunewar3776 4 года назад
Tom pls Upload All Videos Fastly We can't waif for 1 week man
@arkhangelgeos120
@arkhangelgeos120 Год назад
i understand that it is old tutorial but if anyone can help me, problem "Invalid call to func "intersect_ray" in base 'GodotPhysicsDirectSpaceState3d', here the code at whitch i stuck: extends CharacterBody3D var _space_state var target func _ready(): _space_state = get_world_3d().direct_space_state func _physics_process(delta): if target: var result = _space_state.intersect_ray(global_transform.origin, target.global_transform.origin) if result.collider.is_in_group("Player"): look_at(target.global_transform.origin, Vector3.UP) set_color_red() else: set_color_green() func _on_area_3d_body_entered(body): if body.is_in_group("Player"): target = body print(body.name + "entered") set_color_red() func _on_area_3d_body_exited(body): if body.is_in_group("Player"): target = null print(body.name + "exited") set_color_green() func set_color_red(): $MeshInstance3D.get_active_material(0).set_albedo(Color(1, 0, 0)) func set_color_green(): $MeshInstance3D.get_active_material(0).set_albedo(Color(0, 1, 0))
Далее
The biggest lie in video games
15:18
Просмотров 1,8 млн
Я ДОСТРОИЛ ЗАВОД - Satisfactory
19:13
Просмотров 124 тыс.
Х.евая доставка 😂
00:23
Просмотров 801 тыс.
would you eat this? #shorts
00:35
Просмотров 1,8 млн
The Greenwich Meridian is in the wrong place
25:07
Просмотров 820 тыс.
Using Root Motion In Godot 4!
47:41
Просмотров 17 тыс.
How You Can Easily Make Your Code Simpler in Godot 4
6:59
The Jolt Physics Engine
11:23
Просмотров 35 тыс.
They made a game about philosophy...
23:19
Просмотров 458 тыс.
A new way to generate worlds (stitched WFC)
10:51
Просмотров 525 тыс.
Godot FPS Tutorial - Projectile Weapons
14:49
Просмотров 52 тыс.
Optimizing my Game so it Runs on a Potato
19:02
Просмотров 553 тыс.
How To Make A Doom Clone In Godot 4
27:57
Просмотров 75 тыс.
I Made My First Game in Godot in 3 Weeks...
26:21
Просмотров 316 тыс.
Я ДОСТРОИЛ ЗАВОД - Satisfactory
19:13
Просмотров 124 тыс.