Why is raycasting always raycasting at the center point of the game?

Hello There!

As the title says, I’ve created a raycast which is used to replicate that fancy rock ring effect (Or impact crater, I guess) althought it only raycast at the center point at the game rather than the players position.

function Raycast(HRP)
	local RayParams = RaycastParams.new()
	RayParams.FilterDescendantsInstances = {workspace.Debris}
	RayParams.FilterType = Enum.RaycastFilterType.Exclude
	
	local Angle = 0
	
	for i=1, 30 do
		local Size = math.random(2,3)
		local Part = Instance.new("Part")
		Part.Anchored = true
		Part.CanCollide = false
		Part.Size = Vector3.new(1,1,1)
		Part.CastShadow = false
		Part.CFrame = Part.CFrame * CFrame.fromEulerAnglesXYZ(0, math.rad(Angle), 0) * CFrame.new(10,5,0)
		
		game.Debris:AddItem(Part,5)
		
		local Raycast = workspace:Raycast(Part.CFrame.Position,Part.CFrame.UpVector * - 10, RayParams)
		if Raycast then
			Part.Position = Raycast.Position + Vector3.new(0, -5, 0)
			Part.Material = Raycast.Material
			Part.Size = Vector3.new(Size, Size, Size)
			Part.Color = Raycast.Instance.Color
			Part.Orientation = Vector3.new(math.random(-180,180), math.random(-180,180), math.random(-180,180))
			Part.Parent = workspace.Debris
			
			local Tween = game.TweenService:Create(Part,TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0),{Position = Part.Position + Vector3.new(0, 5, 0)}):Play()
			delay(4,function()
				local Tween = game.TweenService:Create(Part,TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0),{Position = Part.Position + Vector3.new(0, -5, 0)}):Play()
			end)
		end
		Angle += 25
	end
end

because your origin is the cframe of a part that isnt even welded or positioned to the player??

Maybe in the line

Part.CFrame = Part.CFrame * CFrame.fromEulerAnglesXYZ(0, math.rad(Angle), 0) * CFrame.new(10,5,0)

You mean to multiply by HRP.CFrame and not Part.CFrame?

I think you forgot to set the raycast origin?

I’ve already fixed this issue a guess a month ago, although I have another issue, want me to show it to you?

I’m not the best scripter, but you can show me and I’ll see what I can do

Okay, here:
Why are my units causing the framerate to drop whenever they kill a bunch of enemies? - Help and Feedback / Scripting Support - Developer Forum | Roblox

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