im kinda new to godot, and i was wondering how to re-create something like this unity project
does anyone have an idea of where i should start, or do?

  • I think an easier option would be to use an Area2D node. You'd put that node under the character and examine new objects as the Area2D detects them using the on object enters area signal. The Area2D (or 3D) would be given a shape like a circle or perhaps cylinder. When you detect an object perform a raycast to see if that object is visible.

    Depending on how your game is designed, you might need to continually raycast towards that enemy or you might be able to do it less frequently.

I would arrange a bunch of raycasts into a fan and I've done this with a rudimentary patrol script using the navmesh in a shooter I'm making. You get the children into an array, then do a for loop and check each array per frame to see if it's detecting anything, use layers to decide what you want the raycasts to be blocked off by or hit. If you ask me I think that's a bit of an overcomplicated solution to the problem.

    Lethn
    i will try to do this, likely wont work with my small brain of knowledge.

      Gloxide It's more simple than you might think.

      var FOVRaycasts = []
      
      FOVRaycasts.append(get_children())

      Bit of a half arsed pseudo code but it's spring time now and I get zonked this time of year, don't put this in a loop, otherwise you'll get infinite raycasts being added to the list and it will probably crash.

      For fovRaycast in FOVRaycasts:
             fovRaycast.isColliding():
                   // Do collision stuff here

      For extra accuracy you could simply add more raycasts, of course this means more processing power being used.

      I think an easier option would be to use an Area2D node. You'd put that node under the character and examine new objects as the Area2D detects them using the on object enters area signal. The Area2D (or 3D) would be given a shape like a circle or perhaps cylinder. When you detect an object perform a raycast to see if that object is visible.

      Depending on how your game is designed, you might need to continually raycast towards that enemy or you might be able to do it less frequently.

      Timer node would work great for the raycast option now you mention it, have it run a collision check however many seconds.

      that should work wonders thanks!
      only other thing would be can i add in functionality for something like this?

      Raycasts usually are expensive so you want to minimize their number, espcially if every enemy is going to be sending them. So you'll want some culling method.

      1. First culling method would be the distance from the target. That's an easy one and would prevent raycasting onto distant targets.
      2. You should be able to find some formula related to circles to know if the target is in the right part of the circle (the FOV)
      3. Lastly you send a raycast from the viewer to the target making sure to remove the target from the list of possible collisions, if nothing collides with the ray then it's being seen.

      On top of that you could have some system to know who's interested in what, kind of like the physics layer, so you don't test against targets you don't care about.