A
A
Afafks1231321321652020-01-15 17:14:54
JavaScript
Afafks123132132165, 2020-01-15 17:14:54

How to do raycasting?

I wanted to make a game using raycasting, I read articles on the Internet and didn’t understand anything, I store the map in a one-dimensional array and don’t know how to cast rays and handle collisions. I’m making a game in javascript and I would like someone to describe the logic itself or tell me what kind I will need mathematics. Help me, otherwise it’s not clear what to do and how it all works in general

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
profesor08, 2020-01-15
@Afafks123132132165

In short, on shaders.
Do you know what a light source is? If yes, then you take from the source point and direct the vector in the right direction. Then you look whether it crosses some objects or not. If it crosses, then you look at what point and at what angle it crosses the first object, send the next vector from this point, and repeat the procedure as many times as you want. Send as many vectors as you want. Since the vector is a ray of light, it has its own color, when it meets the object, its color is mixed with the color of the object, so the object is painted and displayed. The next beam already has the resulting color and is reflected further.
glslsandbox.com/e#52242.4
https://www.youtube.com/watch?v=D-HroAIUePM

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question