How to draw a circle on ground around my 3d character ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By socomajor

Hello,

I try to achieve the following effect :

I have a 3D floor (let’s say a plane, but it could be any mesh) : F
I have a 3D point in space : A
I have a given radius : R

I would want the floor to be red where the distance to A is inferior to R.
The goal is to vizualize the distance to point A (which could be my character for instance) on the ground. Idealy the red zone is semi-transparent so I can see part of the real floor material (but I don’t think this is the difficult part).

From what I understood, I think making a shader could be the answer , but I don’t know how to set the color of the fragment depending on the distance to a 3D point. I would appreciate yout help on this one :slight_smile:

:bust_in_silhouette: Reply From: Alack Sunrider

I would use a shader for that.
With this tutorial you can get the fragment world position. Then you need to check if the distance from the fragment to the player is less than R. This should be in the void fragment() function.

vec3 color = vec3(1., 0., 0.); // RED
if(distance(world_position, player_position) < R){
        ALBEDO = color + texture(SCREEN_TEXTURE, SCREEN_UV).xyz;
        ALPHA = 1.;
    }
    else
        ALPHA = 0.;

Since you want the ground to be visible, the screen texture should be added to the color (like in the example above). If you want to see the floor better, reduce the ALPHA value.
If you are new to shaders, I would suggest following the tutorials here first.