I know its retarded but am i?
So far i have created a Decal, with a texture.
The Decal supposed to do this:
Expand the size of it based on character movement. Cast a ray, get ray length to ground, then set the size of the decal, then offset the decal position = size.y / 2 and it should be visible. on the ground.
What i dont understand is that why its not visible...
I tried many things.. but so fat with no luck.
It is visible once i jump high enough ( further than my raycast) then it gets projected at the end of the green mesh.
extends Node3D
@export_category("Player node")
@export var player_node: CharacterBody3D
@export_category("Shadow distance")
@export var shadow_distance = 10.0
@onready var ray_cast_3d: RayCast3D = $RayCast3D
@onready var shadow: Decal = $Shadow
@onready var mesh_instance_3d: MeshInstance3D = $MeshInstance3D
const BIAS = 0.01
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
ray_cast_3d.target_position = Vector3.DOWN * shadow_distance
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
if ray_cast_3d.is_colliding():
var collision_point_global = ray_cast_3d.get_collision_point()
var collision_point_local = self.to_local(collision_point_global)
var ray_len = (player_node.global_position - collision_point_global) * Vector3.UP
shadow.size.y = ray_len.y
if shadow.size.y < 0.1:
shadow.size.y = 0.3
shadow.position = Vector3(0,0,0)
else:
var haf_size = (shadow.size.y/2)
shadow.position = collision_point_local + (Vector3.UP * haf_size ) + (Vector3.UP * BIAS)# Vector3(0,BIAS,0)
mesh_instance_3d.mesh.size = shadow.size
mesh_instance_3d.position = shadow.position
print("Result: ",ray_len)
else:
shadow.position = Vector3.DOWN * shadow_distance + Vector3(0,BIAS,0)
print("Not")
pass
The goal is to have the blob shadow show underneath the player so that you can see where you are landing. but if the height is higher than the predefined then dont show the shadow..