Godot Version
4.2.2
Question
I have a problem trying to create a “spot shadow” effect for my 3D third person character. the mesh dips into the floor as the player falls down, with it moving further into the floor as the player falls faster. Here is the code for it:
func _ready():
var ray_cast = RayCast3D.new()
ray_cast.target_position = Vector3(0, -ray_length, 0) # Correct property name
ray_cast.collision_mask = 1 # Adjust based on your collision layers
ray_cast.add_exception(self) # Add the player to the exceptions
add_child(ray_cast)
ray_cast.name = "shadow_ray_cast"
ray_cast.enabled = true
# this is getting called in _physics_update()
func update_shadow_position():
if is_on_floor():
shadow_plane.visible = false
else:
shadow_plane.visible = true
# Get the RayCast3D node
var ray_cast = $shadow_ray_cast
# Update the raycast position and force an update
ray_cast.force_raycast_update()
if ray_cast.is_colliding():
shadow_plane.global_transform.origin = ray_cast.get_collision_point()
It does stick to the floor just fine as long as I am moving upward. Not sure how to fix it going downward. Any help would be appreciated