So i have this drone that is supposed to shoot in the direction it is facing. I currently am having a lot of trouble finding the correct articles, posts, etc. that can help me so i decided to post my own. If anyone has a solution or a forum post they can send me a link to that would be much appreciated. If you need any resources such as any screenshots I can provide them as needed.
local blacklist = {script.Parent["Meshes/fbxball"], script.Parent.Barrel, script.Parent.Part}
local rotate = false
function lookAt(eye, target)
local forwardVector = (target - eye).Unit
local upVector = Vector3.new(0, 1, 0)
-- You have to remember the right hand rule or google search to get this right
local rightVector = forwardVector:Cross(upVector)
local upVector2 = rightVector:Cross(forwardVector)
return CFrame.fromMatrix(eye, rightVector, upVector2)
end
function Shoot()
local part = script.Parent.Barrel
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Blacklist
params.FilterDescendantsInstances = blacklist
local raycast = workspace:Raycast(part.Position, part.CFrame.LookVector + Vector3.new(0, 0, 90000), params)
if raycast then
print(raycast.Instance.Parent)
end
end
while true do
script.Parent:SetPrimaryPartCFrame(lookAt(script.Parent.PrimaryPart.Position, workspace:WaitForChild("HyperXchamp56112").PrimaryPart.Position))
Shoot()
wait()
end