Shadow object that uses raycasting drags behind the player instead of going with the player

so i want to make this game with an old 90s game kinda style (sonic adventure games to be specific) and i wanted to make a circular shadow that appears under the character.
so i did just that, and it’s working (so far)

but the problem is that it’s just dragging behind the player for some reason. it’s supposed to stay on the character, but it’s not.

i’ve tried to figure out how to not make it drag but i’ve had no luck so far, and not surprisingly there isn’t anything about this on devforum so here i am.

here’s the script.

local run_service = game:GetService("RunService")
local shadow = script.Shadow

game.Players.PlayerAdded:Connect(function(player)
	
	player.CharacterAdded:Wait()
	
	local character = player.Character
	local root_part = character:WaitForChild("HumanoidRootPart")
	local newShadow = shadow:Clone()
	newShadow.Parent = root_part
	
	local ignore_list = {
		character.Head,
		character.LeftArm,
		character.LeftLeg,
		character.RightArm,
		character.RightLeg,
		character.Torso,
		root_part,
		newShadow
	}
	
	run_service.Stepped:Connect(function()

		local ray_origin = root_part.Position
		local raycast_params = RaycastParams.new()
		raycast_params.FilterType = Enum.RaycastFilterType.Exclude
		raycast_params.FilterDescendantsInstances = ignore_list
		local raycast_result = workspace:Raycast(ray_origin, Vector3.yAxis * -1000, raycast_params)

		newShadow.Position = raycast_result.Position

	end)
	
end)

image

2 Likes

The problem is that you’re using a server script, you should change it to a local script so it updates faster.

Note: try also using RenderStepped when you move the code to the client.

where will i move it? starterplayerscripts?

edit: it worked!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.