I have a aiming system that follows your mouse. The only problem is the raycast is going the opposite direction from the mouse position.
https://gyazo.com/f2eefe0dcaaa3fdafd714f776982c3fb
Here’s my code:
local player = game:GetService('Players').LocalPlayer
local character = player.CharacterAdded:Wait()
local HumanoidRootPart = character:WaitForChild('HumanoidRootPart')
local Mouse = player:GetMouse()
local camera = workspace.CurrentCamera
local Cursor = game:GetService('ReplicatedStorage'):WaitForChild('Models'):WaitForChild('Cursor')
local Arrow = Cursor:WaitForChild('Arrow')
local Circle = Cursor:WaitForChild('Circle')
local Line = Cursor:WaitForChild('Line')
local MOUSE_DOWN = false
Line.Parent = workspace
Mouse.Button1Down:Connect(function()
MOUSE_DOWN = true
end)
Mouse.Button1Up:Connect(function()
MOUSE_DOWN = false
end)
local hitPosition = Vector3.new()
Mouse.Move:Connect(function()
if MOUSE_DOWN then
local unitRay = camera:ScreenPointToRay(Mouse.X, Mouse.Y)
local ray = Ray.new(unitRay.Origin, unitRay.Direction * 1000)
local hitPart
hitPart, hitPosition = workspace:FindPartOnRay(ray, player.Character, false, true)
--print(hitPosition)
end
end)
while task.wait() do
local pos = Vector3.new(HumanoidRootPart.Position.X, 17, HumanoidRootPart.Position.Z - 2)
Line.CFrame = CFrame.new(pos, Vector3.new(hitPosition.X, 17, hitPosition.Z))
end