Godot 3.0: 2D Visibility with Ray-casting

  Рет қаралды 71,612

KidsCanCode

KidsCanCode

Күн бұрын

Пікірлер
@hamzahichmine7084
@hamzahichmine7084 11 ай бұрын
For all these years still this code help people
@eljoagames
@eljoagames 6 жыл бұрын
You are like a hero, the hero of Godot and all you teach is a gift for us. Thank you a lot!!
@josesena4314
@josesena4314 6 жыл бұрын
This is one of the most useful Godot tutorials I've ever seen. Great to se somebody making really original and useful videos. Thank you a lot for this!
@Kidscancode
@Kidscancode 6 жыл бұрын
Thanks!
@daviddalisay5317
@daviddalisay5317 5 жыл бұрын
I love that you did the break at 20:10. I appreciate your video's focus on code quality/efficiency while making an enjoyable game.
@benrainero9796
@benrainero9796 4 жыл бұрын
great tutorial. something to mention is that if the player rotates, their collision shape will rotate as well and you'll need to rotate the corner points around the player position before doing the vector math to get their position in game space
@snstarosciak
@snstarosciak 4 жыл бұрын
I just started getting back into Godot after over a year and been using Godot 3.1 (and now Godot 3.2) and I just went through this video and the best part is after I first investigated the starter code, I actually learned how to do projectiles from turrets (which is something I didn't know how to do) and now understanding how to do this Raycasting stuff is extremely powerful. I've seen it used for tons of other reasons but never fully got how it worked. Thanks again! I love your teaching style which makes it fun to learn about this :D If you were able to do more series on, say a combat system which could utilize this and stuff in some of your other videos, that would be so awesome :) I know combat is a pretty heavily used mechanic in a number of games and seeing how you would set it up and do it would be beneficial for everyone. Cheers!
@idleman5463
@idleman5463 2 жыл бұрын
The tutorial is still very helpful after all the years, thank you.
@noc2_art
@noc2_art 5 жыл бұрын
What a master! And you devise such effective and scalable solutions. Thank you so much for sharing your knowledge with us.
@rafaelgpontes
@rafaelgpontes 6 жыл бұрын
Man, your tutorials are great! Be sure of one thing: you are changing lives, man!!! Keep up the great work. Cheers from Brazil. :)
@MisterBrown94
@MisterBrown94 6 жыл бұрын
Every video is soooo useful. No matter what you cover, I always learn something I didn't know. Thank you a lot!
@indigoblacksteel1176
@indigoblacksteel1176 6 жыл бұрын
You mentioned at the end of this video that a person could do reflections by starting a raycast where the other left off. And then that you could put that into a loop to have it bounce multiple times. I'd love to see one where you showed the code of how to do that efficiently.
@tomanski3767
@tomanski3767 4 жыл бұрын
Thank you so much! Probably the best godot tutorials I have ever seen!
@androskris
@androskris 6 жыл бұрын
Nice, wish I had tutorials like this when I was 15 and trying to code games on my C64 with Gary Kitchen's Gamemaker
@MsKocagoz
@MsKocagoz 6 жыл бұрын
One more great tutorial, with your help I will open my own game studio :)
@Kidscancode
@Kidscancode 6 жыл бұрын
Good luck!
@wearegeek
@wearegeek 6 жыл бұрын
Awesome! One can never have enough Godot tutorials. ^_^
@fossegutten6579
@fossegutten6579 6 жыл бұрын
Very nice video, I prefer these short tutorials over the long series! How did you add custom names to the layers and masks by the way?
@Kidscancode
@Kidscancode 6 жыл бұрын
In Project Settings -> Layer Names -> 2d Physics
@noiJadisCailleach
@noiJadisCailleach 5 жыл бұрын
Added another tool in my arsenal as a game dev. Thanks for this!
@markanthonydelossantos6147
@markanthonydelossantos6147 5 жыл бұрын
great tutorial with clear explation of every code
@thomashalsted1888
@thomashalsted1888 6 жыл бұрын
I needed this video a lot! I'm making a player-controlled turret that fires LASERS. It's fun.
@seishumorales9758
@seishumorales9758 5 жыл бұрын
Hi, thanks for the tutorial super helpful. One problem with my project is the turret doesn't shoot the player when its radius is touching the platform/walls even when the player is in the radius circle. The walls does have a collision2D shape but looking at your project, i am not sure how you made yours work when the circle is touching the walls.
@MINDoSOFT
@MINDoSOFT 2 жыл бұрын
Excellent tutorial and lesson !!!
@elerosvecchio
@elerosvecchio 4 жыл бұрын
Great tutorial! Do you know how you would get the corners of a 3D object?
@Kidscancode
@Kidscancode 4 жыл бұрын
Depends on the collision shape. If you're using a box shape, you can get the extents in the same way as the rectangle.
@gustavofreitas3734
@gustavofreitas3734 3 жыл бұрын
I may be commenting a little bit too late here, but does the turret need to be a kinematic body, or could it be static?
@bubblemage
@bubblemage 2 жыл бұрын
Hello! I wonder if you'd know some tips to give the player a limited vision range, like the player not being able to see through wall tiles and instead just see darkness. I've already tried to achieve this by using Light2D and LightOccluder2D but this doesn't work as I want it to, I guess I don't want a "flashlight" effect, but more like a true ranged vision. The game "twc byond" achieves this, and I'd like to know how to recreate something like that!
@IustinNitza
@IustinNitza 4 жыл бұрын
I'm getting this error 50% of the time - Invalid get index 'shape' (on base: 'null instance'). How could I make sure that get_node('CollisionShape2D') exists before declaring target_extents var ? If I add an if target.get_node('CollisionShape2D') != null I get some weird behaviour. Thx
@mohdseraj1047
@mohdseraj1047 6 жыл бұрын
Cool tutorial, thanks for that! I've a question, how is it possible to make the enemy shoots at you when he only sees you.
@gameplayandreview
@gameplayandreview 5 жыл бұрын
Can you edit it for 3D Environment with a "Cone" Visibility for Enemy (Shape Orientation : point towards enemy and Circle outwards) and "Cylindrical" Visibility for Turret (Shape Orientation : Flat Top & Bottom)? Also can you do an A.I. Pathfinding script.
@RexN6
@RexN6 6 жыл бұрын
Hey! I was looking for something like this!! Thank you very much!
@Kidscancode
@Kidscancode 6 жыл бұрын
Glad it could help!
@FameMonsterD3
@FameMonsterD3 6 жыл бұрын
Can you do this but instead of shooting, have the turrets chase you and melee. I would like to learn how to do that. Great video man as always.
@Kidscancode
@Kidscancode 6 жыл бұрын
Sure. In my example, I'm using the direction of the raycast to set the direction of the bullets. You could just as well use that direction vector to set your mob's velocity.
@Demogooo
@Demogooo 4 жыл бұрын
I have a question. You used your current bit mask layers that you had to know when to stop the ray cast, but I have added another layer and mask layer to my enemy, but the problem is that now if I have multiple enemies chasing me, if one enemy that is tracking my player goes behind another, the line of sight will stop and the enemy in front. How could I specify which mask bits I wanted to detect instead of using all the current mask bits I have selected for my enemy? (In this case I just want the first bit mask and if possible, the second as well)
@AgriasOaks99
@AgriasOaks99 4 жыл бұрын
Sir, can we use raycast to show area of attack? I mean in rpg game when a boss uses skills, normally thare will be circular or rectangular red areas when the attacks will be launched
@peemmai7660
@peemmai7660 4 жыл бұрын
Can you change the circles to a Sector instead?????? Pliz tel me
@xy0157
@xy0157 6 жыл бұрын
great tutorials! also, writing in comments would be good for reinforcement
@feffo9908
@feffo9908 6 жыл бұрын
quick question, how do you give name to collision level?
@Kidscancode
@Kidscancode 6 жыл бұрын
Project Settings -> Layer Names -> 2D Physics
@ejoojoo
@ejoojoo 4 жыл бұрын
Trying to use this on a kinematicbody but got an error "Invalid get index 'position' (on base: 'KinematicBody')."
@クリプトムネシア
@クリプトムネシア 4 жыл бұрын
You need a KinematicBody2D
@memzen8101
@memzen8101 6 жыл бұрын
If it is possible, maybe do a video about a pop up option menu on mobile devices that appears over any level which uses a minimum amount of cpu when it is not needed.
@froyorex4856
@froyorex4856 5 жыл бұрын
Please Make more videos ?
@Kidscancode
@Kidscancode 5 жыл бұрын
I'm working on it. Any requests?
@froyorex4856
@froyorex4856 5 жыл бұрын
@@Kidscancode please make a rocket that follows you and explodes upon contact. Please ! I wanna participate in my first game jam.
@froyorex4856
@froyorex4856 5 жыл бұрын
@@Kidscancode smooth following rocket. With explosion particles.
@Kidscancode
@Kidscancode 5 жыл бұрын
I did that in my tank project: kzbin.info/www/bejne/gXK4gWekoa-ssJI
@OmegaF77
@OmegaF77 6 жыл бұрын
Could you do a tutorial on how to cast shapes? For example, Unity 3D has a kind of raycast called, "SphereCast." It casts a sphere wherever it's pointing. This is perfect if you want to make your own character controller.
@EightNineOne
@EightNineOne 6 жыл бұрын
This is immensely useful. Thank you so very much.
@JeanVermeersch
@JeanVermeersch 5 жыл бұрын
Great tutorial, thanks a lot! :) Question: Do you think we can use raycast2d aswell for something else, like doing a wall jump for example?
@Kidscancode
@Kidscancode 5 жыл бұрын
Certainly. Raycasts have lots of uses. That's one common use of a raycast, although a shape might work better to detect touching a wall. There is also "is_on_wall()".
@JeanVermeersch
@JeanVermeersch 5 жыл бұрын
@@Kidscancode Oh great, thanks you very much! I thought it was possible but I was kinda unsure about it! :)
@johnharbinger4637
@johnharbinger4637 5 жыл бұрын
or you could just create a custom collision bounding box shape one for detect and another for shoot. no rays. no masks. a lot less code (but wouldn't be able to use in different environments without hand making a new detect collision box shape for each placement if positioning to obstacles is different ) just thought be good to mention alternative pro and con.
@mikaelkihlstrand
@mikaelkihlstrand 4 жыл бұрын
Really nice stuff, thanks for this!
@wasimkabir4398
@wasimkabir4398 6 жыл бұрын
Hi Chris! You are awesome!! Could you please make tutorial on creating a top down tile based game in godot 3 (like that you have made for pygame or something new)?
@JAAAA09383-Y
@JAAAA09383-Y 3 жыл бұрын
THANK YOU I WAS STRUGGLING TO DO THISS
@stryker4514
@stryker4514 4 жыл бұрын
Whenever I place my enemy and player character under a Ysort node the detection for the enemy npc doesn't work at all (no lines being drawn). Although if I move it oustide of the Ysort node everything works fine.
@classicguy7813
@classicguy7813 4 жыл бұрын
Can we draw 3d lines draw_line()?
@FeniksGaming
@FeniksGaming 6 жыл бұрын
Great video as always
@cesarfernandez2368
@cesarfernandez2368 6 жыл бұрын
Hello do you any tutorial for light2d? I know the basic but I would like to learn how to do nice light effects
@Kidscancode
@Kidscancode 6 жыл бұрын
Yes, Light2D would be a good one. Have you looked at the code from the official demos?
@cesarfernandez2368
@cesarfernandez2368 6 жыл бұрын
no, not yet. I'm going to see it later thanks.
@rafaeu292
@rafaeu292 3 жыл бұрын
Is there a way, to make a Circular Raycast, or make a Raycast do an instant 360? Because im trying to make a Granade and it would be really helpful for the explosion
@Kidscancode
@Kidscancode 3 жыл бұрын
I'd use an Area2D or `Physics2DDirectSpaceState.intersect_shape()`
@rafaparanhos6285
@rafaparanhos6285 4 жыл бұрын
When I try to run it, it says : invalid index 'shape' (on_base: 'null instance') with value of type 'CircleShape2D'.
@t.h.mgaming4128
@t.h.mgaming4128 3 жыл бұрын
That happens due to files being strange or due to corruption, try restarting your computer or restarting Godot
@Rudyaification
@Rudyaification 5 жыл бұрын
Nice tutorials mate. Got one issue, when i'm using narrow rectangle, it's doesnt work properly.
@Kidscancode
@Kidscancode 5 жыл бұрын
I don't really understand your question. What do you mean by "properly"? What goes wrong? What rectangle is narrow?
@Rudyaification
@Rudyaification 5 жыл бұрын
@@Kidscancode I'm trying to use your concept in my game. Your project works just fine. But in my case i can't get full rotation, it's only works from the left side of the screen. Then i took your code, with all signals, masks... and got the same result. Trying to figure out what is going wrong. Narrow rectangle is like 10 by 70
@Rudyaification
@Rudyaification 5 жыл бұрын
@@Kidscancode Figured out what was wrong. Offset. Just forgot about it. Your code works perfectly! Thanks
@moric4677
@moric4677 5 жыл бұрын
can't we do all of this by creating a raycast2d node?
@3DSNC
@3DSNC 4 жыл бұрын
thanks for the tutorial, that was amazing
@askaranarbekov3145
@askaranarbekov3145 6 жыл бұрын
how did you make the bullets fly out? I do not even have the mob to spin, although I did everything like you
@Kidscancode
@Kidscancode 6 жыл бұрын
Did you connect the shoot signal?
@tomandrieu3876
@tomandrieu3876 6 жыл бұрын
Hey men great tutorial, i search on internet and didn't found how to properly set up the collision mask and i end up with my result.collider.name always returning "EnnemyArea" wich is an area for making my ennemy collinding with a bunch of stuff, my raycast seems to hit this area first. I think if i set up correctly my layerMask it should work but i don't find any tutorial for godot 3 may you help me ?
@Kidscancode
@Kidscancode 6 жыл бұрын
docs.godotengine.org/en/latest/tutorials/physics/physics_introduction.html#collision-layers-and-masks
@tomandrieu3876
@tomandrieu3876 6 жыл бұрын
Thanks man, i got it work with exclude everything in the intersect_ray() method. If i understand correctly i have now two layers name player and ennemy, on my player kinematicBody i set the layer to Player and the mask to Ennemy and the opposite for the Ennemy kinematic body and it will work great ?
@joshdoesthings7836
@joshdoesthings7836 6 жыл бұрын
Keep it up man. Once I start making money, I'll donate brother. But until then thank you
@aleksanderzajkowski8285
@aleksanderzajkowski8285 6 жыл бұрын
"Indentifier not found: pos" in shoot(pos) i dont understand why :( Can someone help??
@Kidscancode
@Kidscancode 6 жыл бұрын
That means you haven't declared a variable named "pos". Perhaps you made a typo?
@TheFAA213
@TheFAA213 6 жыл бұрын
great tutorial ! I was wondering will you do python again ?
@Kidscancode
@Kidscancode 6 жыл бұрын
Sooner or later. There's lots of Python material out there already, and not as much for Godot, and I've gotten very involved with the project so it's my focus right now.
@Condetg
@Condetg 6 жыл бұрын
Hey man. Really thanks for all your tuts. They're insanely good. But for this one it's a bit different. It's good and all, but I'd like to know how it works. So I wanted to reverse-engineered your script. I made a blank project, setup a new character who have different properties than yours. I exported the turrets from your projet and tried to tweak it to make them able to recognize my character... But couldn't make it happen. The turrets don't target this new character of mine and I can't figure out why. For testing purpose I tried to import the character from the ray-casting project to my own... The turrets are able to aim him but do not shoot anything. Is that because importing things from a project to another is broken, or is there specific things in your Main scene or Player that make it works ? I'm going to make turrets step by step after that. But I wanted to try to tweak it a little before trying to code it by myself because I'm a complete beginner with Godot... Once again, thanks for your great tutorials.
@Kidscancode
@Kidscancode 6 жыл бұрын
Most likely you didn't set up your collision layers like I did, and that's why the turrets don't see the player. This really wasn't intended as a beginner-level demo, which is why I didn't go too deeply into the initial setup. It was specifically to talk about the raycasting technique as applied to a common problem.
@Condetg
@Condetg 6 жыл бұрын
Oh, I see. That's pretty instructive anyway. Going to look at it in depth. And... Thanks for your answer btw. :)
@aleksanderzajkowski8285
@aleksanderzajkowski8285 6 жыл бұрын
The thing is i only wanted to do shooting (by main player) and i only use some of your code, and i didn't see var/const pos, so i think it is declared in some other way, dont know where
@Kidscancode
@Kidscancode 6 жыл бұрын
It's a loop variable. "for pos in..."
@aleksanderzajkowski8285
@aleksanderzajkowski8285 6 жыл бұрын
Oh, thanks
@suretmeyenateistoc4252
@suretmeyenateistoc4252 3 жыл бұрын
please make raycast3d tutorial :(
@gitprophet
@gitprophet 5 жыл бұрын
Great explanation. thanks
@av088r
@av088r 6 жыл бұрын
How would I go about scaling this down to 32x32 tiles? I have tried but the raycast messes up and hits walls before it actually collides with them.
@Kidscancode
@Kidscancode 6 жыл бұрын
Tile size should not matter. However, you can't just scale a TileMap - you have to use 32x32 tiles.
@av088r
@av088r 6 жыл бұрын
@@Kidscancode I changed the tilemap cell size to 32 along with editing the icon.png down to 32x32 and fixing all of the scalings of the turret and player but now the ray is stopped by some invisible collider I can't find. Here is what I am seeing: imgur.com/VwBnBEr
@Kidscancode
@Kidscancode 6 жыл бұрын
The TileSet itself needs to be rebuilt with 32x32 tiles and collisions. You're using tiles with 64x64 collisions on a 32x32 map.
@av088r
@av088r 6 жыл бұрын
@@Kidscancode I had to reimport the icon.png to get it to see that it was 32x32 and fixed the shape offset. I am very new to this engine and am trying to learn stuff as I need it.
@muthukrish1318
@muthukrish1318 6 жыл бұрын
i could not get the result.collider.name to be compared with the player object. is there any solution to it.. i used player_node = get_parent().get_node("Player") could not compare if result.collider.name == player_node or "Player" or player_node.get_node("PlayerBody") #its collision name could u help me out ASAP.. Thanks in advance..
@Kidscancode
@Kidscancode 6 жыл бұрын
What does "could not get it to be compared" mean? Did you get an error message? Was your code identical to the code in the tutorial? I can't suggest a solution without knowing what the problem is.
@touqui8659
@touqui8659 2 жыл бұрын
i get : Script inherits from native type 'CollisionShape2D' so it can't be instanced in object of type 'Area2D' when i run my game now :(
@Kidscancode
@Kidscancode 2 жыл бұрын
You seem to have taken a script that starts with "extends CollisionShape2D" and attached it to an Area2D. A script attached to an Area2D must start with "extends Area2D".
@touqui8659
@touqui8659 2 жыл бұрын
@@Kidscancode yeah exact ty man 😋
@Romeoill
@Romeoill 6 жыл бұрын
thank for the best video ever in your channal i like it THAKYOU ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ i love this channel
@OsamaBombLyrics
@OsamaBombLyrics 5 жыл бұрын
First off thank you very much for taking the time to make these videos. Is this compatible with 3.1? I got to the section about adding the directions and received and error on this line: var ne = target.position + Vector2(target_extents.x - target_extents.y) The error reads as follows: error(34,29): No constructor of 'Vector2' matches the signature 'Vector2(var)'. If anyone reads this and/or replies I appreciate it.
@nailbomb420
@nailbomb420 5 жыл бұрын
You're missing the comma between the two numbers in your vector2. The y is supposed to be negative, not taken away from the x
@OsamaBombLyrics
@OsamaBombLyrics 5 жыл бұрын
Thank you very much for your response. I've been staring at this code for far too long. Hey so on line 27 he has the following line: var target_extents = target.get_node('CollisionShape2D').shape.extents - Vector2(5, 5) Would this still work with a CollisionPolygon2D? @@nailbomb420
@nailbomb420
@nailbomb420 5 жыл бұрын
@@OsamaBombLyrics No it wont work with a polygon, it's specific to the rectangleshape2d, i.e they're different properties for the different shapes, circleshape2d has radius instead for example. If you used polygon for no real reason, just swap it to a rectangleshape2d, if the polygone is fairly important to the shape of your character, then consider adding an area2d with a rectangleshape and using that for basic stuff like this. When it comes to most collision you will find it much much easier to use rectangles or circles, as the maths is quite simple to figure out intersections. Ass soon as you start to rotate things or use odd shapes it means either alot more more work, or higher level of maths :/ (which is annoying) So I suggest using rectangles where possible. Note, that you can make the rectangle much smaller than the size of the sprite, i.e many 32x32 sprites can have rectangleshape colliders 16x16 or some other dimensions. Hope this helps.
@nailbomb420
@nailbomb420 5 жыл бұрын
@@OsamaBombLyrics here's a link to the polygon2d class documentation: docs.godotengine.org/en/3.1/classes/class_polygon2d.html the polygon does store all the points that define it, so you could in theory get that list of points and use them instead of the rectangleshapes extents, as they're both just points in space. Might be worth checking out.
@OsamaBombLyrics
@OsamaBombLyrics 5 жыл бұрын
@@nailbomb420 Yessss! I got it working! Thanks for the tip and responses! I just used another CollsionShape2D on the Player with its roll to specifically handle interacting with the Turret. I will probably take your advice and switch my CollsionShape2D's to either rectangles or circles. I was using the Polygon2D shapes because I wanted all the collisions to be as exact as I could make them. However, if it will be just a bigger headache in the long run I will just keep things simple. I'd rather have a working game then nothing at all.
@raremc1620
@raremc1620 6 жыл бұрын
Hi. How could i contact you? I need some help with python.
@Kidscancode
@Kidscancode 6 жыл бұрын
There's a link on my website to send me email. Or you can post here in the YT comments if it's a relatively short one. I can't promise I can help you, but I'll take a look.
@Chevifier
@Chevifier 5 жыл бұрын
This is awesome
@dand809
@dand809 5 жыл бұрын
this is gold!
@sh_tposter
@sh_tposter 4 жыл бұрын
Man u genius, thanks a lot.
@peedtron
@peedtron 2 жыл бұрын
ur the best 👍
@avvvqvvv99
@avvvqvvv99 6 жыл бұрын
you're the best
@NahomyUchija
@NahomyUchija 6 жыл бұрын
Amazing!!!!
@ryzhucks4624
@ryzhucks4624 6 жыл бұрын
ty
@Pspisripoff
@Pspisripoff 6 жыл бұрын
Awesome!
@classicguy7813
@classicguy7813 4 жыл бұрын
More, give us more
@романярошенко-ц8ъ
@романярошенко-ц8ъ 6 жыл бұрын
красава !)))))))
@truelion-rt6gd
@truelion-rt6gd 5 жыл бұрын
Bad language choice,
Godot 3.0: Splitscreen Multiplayer
15:46
KidsCanCode
Рет қаралды 24 М.
Why Majora's Mask's Blue Dog Took 25 Years to Win the Race
21:04
Vidya James
Рет қаралды 1,9 МЛН
It’s all not real
00:15
V.A. show / Магика
Рет қаралды 20 МЛН
Правильный подход к детям
00:18
Beatrise
Рет қаралды 11 МЛН
We Attempted The Impossible 😱
00:54
Topper Guild
Рет қаралды 56 МЛН
To Brawl AND BEYOND!
00:51
Brawl Stars
Рет қаралды 17 МЛН
Why I'm Moving To Godot In 2025
14:23
Acerola
Рет қаралды 137 М.
Godot 3.0 - Know Your Nodes: Particles2D
18:14
KidsCanCode
Рет қаралды 86 М.
How to Use SIGNALS Correctly in Godot 4 (everything to know)
24:06
Minecraft Without Jumping, but Auto-Jump is on…
15:08
GuyBordo
Рет қаралды 1,3 МЛН
I Made My Dream game In Godot 4... #devlog 1
8:03
PinoPrime
Рет қаралды 281 М.
I Made a Game in Desmos
8:30
Jake Walker
Рет қаралды 41 М.
Godot 3.0: Top-down Tank Battle - Part 1
19:36
KidsCanCode
Рет қаралды 105 М.
How to use Resources in Godot 4
8:08
Bitlytic
Рет қаралды 8 М.
The Best New Feature in Godot 4.4*
7:06
Gamefromscratch
Рет қаралды 26 М.
Every 2D Node Explained in 9 Minutes !
9:19
Lukky
Рет қаралды 390 М.
It’s all not real
00:15
V.A. show / Магика
Рет қаралды 20 МЛН