Raycasting or Shadowcasting - html5 games?

Is there a way to check if there is a wall between a player and an enemy - to check if the enemy can see the player.

Like this:
scirra.com/tutorials/902/li … raycasting

1 Like

Shadowcasting is better. You can use it to find the visual radius of any character you want.

Quick version from Google code: code.google.com/p/js-like/wiki/ … dowcasting

Full (and excellent) tutorial here: blogs.msdn.com/b/ericlippert/arc … t-one.aspx

You can also do some hackish ways that I will mention, but not recommend, of checking direct distance. e.g. Fire an invisible test shot towards the player and see if that can make it or generate a line of invisible sprites in a straight line towards the player and see if anyone of them have a collision.

can we then get shadowcasting as a condition logic block in gdevelop? I really need it in order to do AI.

Combined with the already excellent pathfinding it will make gdevelop an amazing tool for game developent. :smiley:

Also, at the development section of the forum, could you please make a tutorial on how to insert java script in gdevelop. Then make a tutorial on how to write new add ons for it :slight_smile:

We need to get more people to submit code

Shadowcasting is quite a large algorithm and is also much more rarely used than something like path finding. I don’t think it would be a worthwhile use of time to try and add a template for something like this.

i just want a condition to check if there is a wall between two objects. :unamused:

c2 does it easily. it is often used for ai. cant do proper ai without it.

witout that check it is obvious that your ai has no ai. It shoots at a wall when you are behind it. You cant even tell it to walk to the other side of the wall (path finding) when the player runs behind a corner.

So yeah, without raycasting I dont think you can make an AI that works. I can think of a hacky way to do it, but it would eat too much resources and probably create other issues.

If your game doesn’t consist of many enemies and features only shooting in straight lines at the player (or a straight line predicting the movement of the player) within a given circular range (or any range) then you can just fire fast bullets at the player to see if a shot is there.

For one enemy:

Timer “shottimer” is equal to 0.9s || Fire an invisible bullet straight at the player. Report the result 1 = hit / 0 = miss.

Timer “shottimer” is equal to 1.0s || Fire at player.
result = 1

For many enemies: Use linked objects to link the shots and enemies and report the result to a variable that belongs to enemy, so each enemy gets its own results and makes its own decisions.

that is a lot of ifs . Are you saying that everyone doing an AI should not have feature X and Y on gdevelop, thus be limited by the engine’s capabilities because raycasting is missing?
The fix is akin to what you would do in multimedia fusion. :unamused:
I already have an AI there with the line solution.
No idea how to do the line approach in gdevelop.

You need to also assign a custom ID to the raycast object (stretched line), in order to check whose enemy is it from. You gotta make a whole bunch of objects on top of the ones you would also need- such as a cone of sight collision.

It is an ugly ugly fix to a simple problem. Thus why I make the feature request of a raycast functionality.
This is way cleaner to do in construct 2 and a mess in multimedia fusion. If gdevelp devs settle for hackish solutions to a common feature, the engine will be more like mmf.

Its not only for AI either. What if you want to make a game where the player’s visibility is limited by their position. For example they cant see the room behind a closed door.

ondras.zarovi.cz/games/js-like/

How much harder/impossible would it be without raycasting?

The solution I reposed to your problem is only a few lines long, much more efficient than ray-casting and works. It’s not really a hack…

For this, implement the shadowcasting algorithm.

I’ve seen C2 has some big problems with efficiency in games, probably because algorithms like raycasting are thrown in there and used by people without any thought about if it is the most suitable thing to be using or how efficiently it will run.

i cant really implement shadowcasting. I am not experience enough :unamused:

Doesnt gdevelop have a feature that shows which event is using up resources?

You can go on profile performance at the top of the page (only available on native platform).

You should give the shadow-casting a try. You can ask endless questions about things that are not working on the forum here if and when things go wrong.

Anyway, at this point in the thread I’m really confused how your problem isn’t solved. :confused:
What exactly is your game requiring? Then maybe something to fit your exact needs can be proposed. I think raycasting is one of the worst things in game programming ever… And that there should almost certainly be a more efficient (and perhaps easier) solution.

a copy of the raycasting feature in construct2 :laughing:

But nevermind, I can shoot an object. I suggested a number of other features which I find more important.

shadowcasting would be so damn sweet though. I really want to make a stealth game prototype with gdevelop.
Right now I am striggling with bugs I keep finding in the editor.

You can do a workaround to simulate raycasting, check the “Lazer and zombies.gdg” example. It uses a while loop to put an object and move it fast/“instantly” until it collides. The raycasting precision can be improved with a smaller sprite for collision detection, and moving it “slowly” through the loop (smaller steps, lower performance) :slight_smile:

Shadowcasting (please don’t kick me :smiley: ) could be performed through multiple raycastings, of course it’s a very-poor approximation :frowning:
Anyway, you can improve the precision increasing the number of directional raycastings, again, at cost of performance.

EDIT: Changed “Raycasting” with “Shadowcasting” in the scond paragraph.

maybe get this into gdevelop:
github.com/eXpl0it3r/LTBL


And use it in a creative way- to bring light to completely dark areas in the game as you walk through them (flashlight effect)

This would be great for horror games