Solving the shadow problem and its alternative

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

Hello! I was faced with the problem of rendering shadows in Godot and I had a question how exactly can I fix this?
Imgur

However, while I was trying to change something, I came across one idea. Make the shadows by hand. Like this:
Imgur

But the following question arose: how to realize the rotation of this sprite from a light source so that the artificial shadow behaves realistically?

I tried to use Area2D, but this does not work correctly

You could make vector calculations with the location of the light and the object (e.g. rock.global_position.angle_to_point(light.global_position) gives you Vector2 — Godot Engine (stable) documentation in English), and get the rotation of the object. But it seems complicated - but doable - to get the shadow’s rotation and length from these. You would also need to create several shadows based on direction (e.g. one with light between the characters legs and one w/o).

1234ab | 2020-03-26 11:54

Is it possible to do this if the player and the light source are created by separate scenes, without creating a global singleton?

JerryHayat | 2020-03-26 16:22

Well I’m not an expert but you could avoid using a global singleton with groups (Scripting (continued) — Godot Engine (3.2) documentation in English).

1234ab | 2020-03-27 17:26