RayCasting groundcheck

I want to make so the canister checks the ground, finds part that is ground rn using raycast and sets canister’s position above the ground (Like, stands on the ground, lays on it)

-- Issue is here
local connection
connection = re.OnServerEvent:Connect(function(plr)
	if plr.Character:FindFirstChild("Humanoid") and not bounced and plr.Character:FindFirstChild("WhaleTank") then
		
		local rayOrigin = Middle.Position
		local rayDirection = Vector3.new(0, -10, 0)
		local raycastResult = workspace:Raycast(rayOrigin, rayDirection)
		if raycastResult and raycastResult.Instance then
			bounced = true
			prompt.Enabled = true
			local char = plr.Character
			char.Humanoid.WalkSpeed = 16
			animationTrack:Stop()

			local weld = char.Torso.WeldConstraint
			weld:Destroy()
			model.Parent = workspace
			Middle.Anchored = true
			model:SetPrimaryPartCFrame(CFrame.new(char.Torso.Position + char.Torso.CFrame.LookVector*2))
		end
		delay(0.5,function()
			bounced = false
		end)
	end
end)

I can’t make that work, lol.

I haven’t tried much yet, I’m open to your suggestions and help.

2 Likes

It should be in front of the player and on the ground

model:SetPrimaryPartCFrame(CFrame.new(char.Torso.Position + char.Torso.CFrame.LookVector*2))

Do I have to use here something like:

model:SetPrimaryPartCFrame(CFrame.new(char.Torso.Position + char.Torso.CFrame.LookVector*2 - raycastResult.Instance.CFrame.LookVector))

Well, I found solution.

local distance = Middle.Position.Y - raycastResult.Instance.Position.Y
model:SetPrimaryPartCFrame(CFrame.new(char.Torso.Position + char.Torso.CFrame.LookVector*2 - Vector3.new(0, distance, 0)))

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