Object Positioning Help

bluePart is meant to be the midpoint between the red and green parts so it would revolve around the character however it just revolves around the worldOrigin.

the red part is the result of a viewport mouse raycast and the green part is just the head position raised up 5 studs

main function:

local function RenderPreview()
local mouse = UIS:GetMouseLocation()
local mouseray = camera:ViewportPointToRay(mouse.X, mouse.Y)
local raycastparams = RaycastParams.new()
raycastparams.FilterDescendantsInstances = {player.Character}
local raycastresult = workspace:Raycast(mouseray.Origin, mouseray.Direction * 1000, raycastparams)
if raycastresult.Position then
local direction = raycastresult.Position - head.Position


	part.Position = raycastresult.Position

	part3.Position = head.Position + Vector3.new(0,5,0)
	
	part2.Position = direction
else

end


end

Midpoint huh?
Okay here is something that MAY work:

local raycastparams = RaycastParams.new()
raycastparams.FilterDescendantsInstances = {player.Character} -- recommended to keep this outside
local function RenderPreview()
	local mouse = UIS:GetMouseLocation()
	local mouseray = camera:ViewportPointToRay(mouse.X, mouse.Y)
	local raycastresult = workspace:Raycast(mouseray.Origin, mouseray.Direction * 1000, raycastparams)
	if raycastresult then -- don't use result.Position, it could lead to errors.
		local direction = raycastresult.Position:Lerp(head.Position,0.5) -- the midpoint between the two positions.
		part.Position = raycastresult.Position
		part3.Position = head.Position + Vector3.new(0,5,0)
		part2.Position = direction
	else
		-- something
	end
end
1 Like

Awesome

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