So is there a way to make a tool thats a missile, and it finds the closest object even if your mouse isn’t hovering on it and it locks on and when you shoot it, the missile goes to that object.
well you could grab all the objects in the workspace that isn’t either 1. you 2. terrain. and then find the one with the closest XY to the missile using pythagorean theorem and somehow 3D space
Ok, quick question. Would i get use getchildren to get all the parts in workspace?
Here is how i’d do it.
Firstly, you can have a Value inside of every object you want the missile to follow. I’d name it “HomingValue” (You can make it a boolVlaue and set it to true. If this value is true, then a missile can lock onto this object and follow it).
when the missile is launched, you can have a loop that will search for the homing value inside each object in workspace
for i, v in pairs(workspace:getchildren()) do
if v:FindFirstChild("HomingValue") then
if v:FindFirstChild("HomingValue").Value == true then
local object = v
if (missile.Position - object.Position).Magntiude <= maxDetectionRadius thehn
--Follow the object
end
end
end
end
btw just saying if the thing u want it to home on has specific properties (like it has humanoid) or is set (amnt will not change, item will not change), then you can instead either
if they have specific properties:
dont need homing value, instead just check if the item has the property
if they dont change:
make a list at the start of the game instead of making it every time
Ok tysm, i will try this tomorrow.