hi im ctg i need help
im making this type range for my td game
the video is in somewhere i found*
local ray = Ray.new(Tower.Range.Position, Vector3.new(rangeVal,Tower.Range.Position.Y,rangeVal))
local PartFound, Pos = workspace:FindPartOnRay(ray)
if PartFound then
print("Target Near")
end
the script didnt print part in range except it touch a part
also i wanna ask how i can make it union like in the video?
It isn’t a union. Those are many many smaller parts that are close to each other and they build a circle. It is hard to visualize. You can see in this video that it look like a union but it just a lot of smaller parts.
In the video he probably makes 360 rayscasts and that because a full rotation around the part is 360° (full circle).
So he makes a raycast from the part in the direction the part is looking, then he looks how far the raycast has come for example 20 studs and then creates a part that is 20 studs long and sets its position to the rays position. (You basically visualize the raycast with a part)
After that you rotate the part 1° and repeat what I said before (I believe in the third paragraph) and when you do that 360 times and rotate the part 1° and make a ray and visualize it with a part you can get that effect.
I am sorry if is hard to understand, if you don’t understand something message me as soon as possible and I will try to help you by making a video or something.
local observerPart = workspace.Object -- object that will raycast around itself
local ignoredObjects = {} -- objects that ray ignores
local range = 5 -- range of ray
local raysAmount = 360 -- amount of rays that will be casted around the object
-- :: Create parameters for raycasting
local usedParams = RaycastParams.new()
usedParams.FilterType = Enum.RaycastFilterType.Blacklist
usedParams.FilterDescendantsInstances = ignoredObjects
local pi = math.pi
local function doRaycast(degree)
-- :: Calculate direction based on angle
local degreeToRadian = (degree / raysAmount) * pi * 2
local direction = Vector3.new(math.sin(degreeToRadian), 0, math.cos(degreeToRadian)) * range
-- :: Return raycast results
return workspace:Raycast(observerPart.Position, direction, usedParams)
end
local function instanceFound(result)
local instanceHit = result.Instance -- Instance that got hit
-- :: Do something with that instance
end
-- :: Constant loop, 60 times per second
while task.wait() do
for degree = 1, raysAmount do
local result = doRaycast(degree)
if result then
instanceFound(result)
end
end
end