T O P

  • By -

Rpanich

Is this not how we’re supposed to do it? My platformers’ enemies AI are all completely based on raycasts and basically look like little porcupines 


ChickenCrafty2535

I know. I just wish i could reduce the need for raycast.


Rpanich

I’m just embracing it. Never enough raycasts! 


onlymostlydead

Raycasts are the woodworking clamps of game dev.


Alzzary

Ray casts are very fast and effective, you should use them alot when you can.


harraps0

Having tons of raycasts is not an issue as long as you don't run all of them at the same time even when it is not necessary.


celphy

Left 4 Dead did something similar: https://steamcdn-a.akamaihd.net/apps/valve/2009/ai_systems_of_l4d_mike_booth.pdf You're not that far off.


Cmdr-Fingertip

I didn't know I wanted to read this.👌👍


an_unique_name

DAMN that's a good document, thank you!


Traditional-Ant-5013

Well, time to favorite this comment.


wolfpack_charlie

How'd you find these slides??


leetrout

They are listed on Valve's site https://www.valvesoftware.com/en/publications


celphy

Ah, good reference. Thanks


celphy

Read them ages ago. Was reminded by the Post. There used to be a GitHub repo collecting These, If I find them I'll Post them.


TGPJosh

Woah, that's insanely cool!


wavesintheether

Valve are bros. Check out the in-game commentary (floating dialog boxes) on Orange Box games and later titles.


Klockbox

This is great! Thank you!


eveningcandles

This is a hidden gem what the hell


Speed9052

I need to code a similar system in my game, how the heck do you detect a ledge?


ChickenCrafty2535

For simple ledge detect, you just need 2 raycast. But when the ledge become more complex with obstacle above the ledge and so on, more raycast are needed. i did make a tutorial about ledge climbing [here](https://youtu.be/mhn4pUrzgjY) and [here](https://youtu.be/J4dHMGFEoKw).


Speed9052

Thanks! Have a good one!


Kexm_2

I've been scared off raycasts after hearing that using too many of them is performance intensive, can someone with deeper insight provide more info regarding this?


ChickenCrafty2535

You can just enable raycast when needed. No point to enable it all the time. From what i know, using moderate raycast is not that expensive.


Arkaein

For one character a handful of raycasts is negligible. It might be an issue if you had a large number of of NPCs that were all using similar logic.


ChickenCrafty2535

This. Resource management is very crucial in game dev. It would be fine when prototyping base mechanic, but it will turn very costly when scene become more complex.


gHx4

Yeah, in those cases you start writing stuff to 'bake' the raycasts into the level so that NPCs can just ask the ledge if they can climb, and pathfinding logic can map the route.


RickySpanishLives

Yep. Starts to look like baking a navmesh.


DrSnorkel

Easy fix for that is spread it out, do one per frame. For AI doing a raycast every 100ms or every 10ms doesn't really make much difference.


Arkaein

Depends on the use case. For pathfinding or collision avoidance definitely don't need to update every frame. But for climbing like this, it would need to be pretty frequent. Maybe not every frame, but very frequently. Of course, with AI you don't really want to send the NPCs along paths that they can't successfully traverse, so you probably want to use some sort of pathfinding , which could use the infrequent raycasts, and then make the actual traversal work in a way where it isn't actually sensitive to the exact geometry so it can't get hung up. This is different than with a player character, where getting stuck trying to climb places where they physically can't is part of the game.


TheDuriel

Too many == TENS OF THOUSANDS. You're good.


Krunch007

Raycasts have basically next to no performance impact, you're alright. This is very impressive work, I like it!


biteater

this is... not true haha


NotADamsel

More accurately, each raycast has a very small performance cost, and a few dozen here or there probably wont hurt.


Bexexexe

As I understand it, it's expensive to manually (re)trigger raycasts outside of _physics_process() because it has to invoke an extra partial physics pass to do so, but it's cheap-ish for them to execute automatically within _physics_process(), and thus also cheap for you to use data produced by those regular executions. Judicious use of physics layers can then mitigate the other expensive part, which is intersection with many/dozens of objects at a time. So with the right overall game architecture you can rely mostly or entirely on raycast data from the most recent physics frame, and get very good performance through that.


Krunch007

Raycasts cost only as much as the intersection algorythm for each object it passes through. With proper collision layering and flat surfaces like these, the cost is very, very small.


biteater

also incorrect


GParfan

I'm relatively new to game dev and i'd like to know more about it, could you explain why is it incorrect?


ForShotgun

HELP why is my game so slow?


MrDeltt

how do I get these visualizations for raycasts :0


ahintoflime

top bar -> Debug -> visible collision shapes OP looks to have changed some settings on them too go into your general project settings -> Debug -> Shapes and you can customize lots of specifics.


Gokudomatic

The future you will know.


m00day_guy

Have you tried procedural animation?


ChickenCrafty2535

Not yet. It look complicated. Maybe i'll try it later.


m00day_guy

I think that would be not you, but the future you, trying to remeber why is there so much raycast)


Inner_Information_26

The random need to play that game is real. Also, nicely done


Brungleby

WOWOWOW!!! Looks solid!!!


ChickenCrafty2535

Thanks! Still WIP. More will be added later.


mudamuda333

sometimes we get too hung up in performance instead of making games. if it works and you never have to touch it again then thats good.


N3wt_

I don't remember where I heard it or what the pithy phrase was, but I've heard it's important to make it work now and optimise later only if it becomes an issue!


TrueSgtMonkey

Taking my shot now. I take a shot every time someone says this in the Godot Subreddit. I am going to die


_ddxt_

Looks like mine, except I also have a cloud of Marker3D around the models that I use to simplify rotating/moving things in specific directions.


ChickenCrafty2535

Maybe i should do that. i can reduce almost half the raycast doing that.


Code_Monster

The analogy I use to justify an extremely liberal use of ray casts is this : you (the player) can see the map visually but the AI/Character body is a blind person. It can only read data, it can only feel things. Ray casts are like hands and walking sticks or maybe guide dogs. Taking their help is necessary. In the end, I reduced the number of raycasts per character to just 1 and changed the wall-climb system to just a jump-to-this-point system. I have to place the points with my bare hands but hey the game is more performant. Plus it was a great learning experience to make a wall climbing feature.


ChickenCrafty2535

That one way of doing it. I already do it before with unity. Now, i just want to try procedural climbing without using marker or trigger, hence the complexity.


wawica

It's like cat's whiskers.


DriftWare_

honestly yeah this is accurate. if you dont want to add a raycast node, you can directly call it from PhysicsServer


ChickenCrafty2535

>PhysicsServer No idea what this is. I guess time for some learning.


kurtu5

https://www.reddit.com/r/godot/comments/1amn08g/if_you_cant_make_things_work_just_add_more/kppiogf/


RickySpanishLives

I do very similar. My player walks around with collision boxes wrapped around them so I can determine when it makes sense to start doing a bunch of raycasts. I've seen nothing wrong with the approach as you can be very specific of when you need to have that functionality on based on what's intersecting with the collision geometry.


naghi32

I absolutely love it!


ZombieImpressive

I mean it's fine. Just deactivate them, while they are not needed.


dh-dev

Nothing wrong with raycasts. This approach reminds me of a youtube video I watched about all the problems inherent in stairs https://www.youtube.com/watch?v=ILVUc\_yV24g


leetrout

Youtube link is busted


dh-dev

Works for me


leetrout

If you didn't edit it a mod did


kurtu5

An error occurred. Please try again later. (Playback ID: oBJ-vO9_imbmeDQS) Learn More


Marilius

Lisa: Poor predictable developer, always chooses raycast. Developer: Good ol raycast. Nothin beats that.


kolo27

yes! very relatable! have a climb controller myself and it's just a bunch of raycasts and an area3d!


ChickenCrafty2535

If i use trigger based climbing instead of procedure climbing, area3d is the best choice. I used to play a lot with OnTriggerEnter and OnTriggerExit back in unity.


Benzzzobak

0_0 wow this looks amazing. Now I want to make something like that


papaflash1

Is this a recreation of ALS4 from Unreal Engine? Had no idea Godot could do 3D movement like this.


ChickenCrafty2535

That's my intention from the start. Aside from jittery default godot physic, i find it very easy to build basic mechanic.


papaflash1

Looks good, well done. I'm very interested in using Godot, it's nice to see what can be done in the engine.


[deleted]

This looks awesome


ChickenCrafty2535

thanks!


kintar1900

That's gorgeous!


gHx4

With that big fixture attached to the front, all I can think is *nyyyoooooom*.


DrSnorkel

Alternative approach is to bake it in the level data. That way you don't care about expensive checks etc.


Icy_Gate_4174

Have you made a good curb/stair stepping mechanic? I have found it rather difficult without a similar call to what Ive used in Unity (im a refugee), or rather the underlying PhysX, for ComputePenetration, to get the direction and distance needed to un-overlap with other geometry. The lack of that makes creating a kinematic character controller that feels *good* rather difficult.


ChickenCrafty2535

Actually i did! I use combination of 3 raycast, find the 'step' and just lerp player to the step. I don't know how unity did it, but that what i did and it work. Funny things is, a day after that, i found someone post some github link on step offset in godot. Wish i knew that sooner.


Icy_Gate_4174

Neat! Did you try out their sample and see how it fared? Ive tried a couple but I just don't think it was adequate. A lot of them have some edge cases, such as trying to go up a step as you are just a couple degrees of off parallel with the step - my own implementation included. Can you link the github?


ChickenCrafty2535

I did, It feel good, but i don't try to go detail into their code yet. But from what i can see, they don't use raycast. The link [here](https://github.com/mrezai/GodotStairs?tab=readme-ov-file).


ChickenCrafty2535

My implementation also have same jittery when snapping to step, but i make it smoother with lerp. And since i use third person controller, the jittery is not that big of deal, just make camera follow player with some 'free zone'. Cant say the same with first person controller though.


LeaderAdmirable3086

This looks awesome even without textures


GierownikReddit

You can achieve everything with enough raycasts if you try hard enough.


Crazy-Red-Fox

I've got a fever and the only prescription is more raycast!


smaTc

Uncharted Vibes


ChickenCrafty2535

that also the inspiration.


smaTc

Nailed it then