Im making something where a part follows the position of the mouse if there’s a mouse.Target. However, Im having a difficult time finding out how I would rotate it accordingly. Could I get any lead/guidance on how to do it?
what I mean:
I want the circle to be on the wall instead of inside it
You can shoot the ray from the mouse’s position to the mouse’s target and do something like
if ray then
local hit, pos, normal = ray.Instance, ray.Position, ray.Normal
YourPart.CFrame = CFrame.new(YourPart.Position, YourPart.Position + normal)
end
Lemme know if I did something wrong as I didn’t test it inside studio yet
hmmm. Doesn’t seem to be quite working. Maybe I did the raycast wrong?
local ray = workspace:Raycast(Player.Character.Head.Position + Vector3.new(2,0,0),Mouse.Hit.Position)
if ray then
local hit, pos, normal = ray.Instance, ray.Position, ray.Normal
Module.CFrame = CFrame.lookAt(pos, pos + normal)
end
You need to use a unit vector for your direction that points towards mouse.Hit.Position
local raycastRange = 10 --10 studs long raycast
local origin = Player.Character.Head.Position + Vector3.new(2,0,0)
local direction = (Mouse.Hit.Position - origin).Unit * raycastRange
local ray = workspace:Raycast(origin, direction)
Connection = RunService.RenderStepped:Connect(function(DT)
local raycastRange = 100 --10 studs long raycast
local origin = Player.Character.Head.Position + Vector3.new(2,2,0)
local direction = (Mouse.Hit.Position - origin).Unit * raycastRange
local ray = workspace:Raycast(origin, direction)
if ray then
local hit, pos, normal = ray.Instance, ray.Position, ray.Normal
Module.CFrame = CFrame.lookAt(pos, pos + normal)
end
end)
end
everything you said was right, but the problem was you can’t exactly do this on a circle. (since the “front” side isnt the face of the circle). What I did was made a cube part and welded the circle to the front of the cube. Thanks!