Recently I’ve been trying to make a part that will spawn in the sky and slowly come down. It was supposed to stop moving and unanchor itself once it reached the ground. However instead the part would continue and clip through the ground. I’ve been trying for hours trying to find a solution and have yet to find one. Any help is dearly appreciated! thank you!
Script:
local mod = require(game.ReplicatedStorage.Modules.EffectMod)
local TS = game:GetService("TweenService")
local part = script.Parent
local Flying = false
local CreatingSphere = false
local ForwardMovement = part.CFrame.LookVector * 0.5
local DownwardMovement = Vector3.new(0,-1,0)
local MovementSpeed = .1
local function CreateSphere()
--unrelated
end
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if Flying == false then
local Char = hit.Parent
--also unrelated
end
elseif hit:IsA("Part") or hit:IsA("Model") then
if Flying == true then
Flying = false
part.Anchored = false
CreateSphere()
print("Part touched")
end
end
end)
part:GetPropertyChangedSignal("Parent"):Connect(function()
if part.Parent:IsA("Folder") and (part.Parent.Name == "Aether" or part.Parent.Name == "Folder") then
part.Anchored = true
if Flying == false then
Flying = true
CreateSphere()
while Flying do
local NewCFrame = part.CFrame + ForwardMovement + DownwardMovement
part.CFrame = part.CFrame:Lerp(NewCFrame, MovementSpeed)
task.wait()
end
end
end
end)
does the part have canCollide on?
yes, both the baseplate and moving part have cancollide on. They’re both anchored as well
Touched events can not fire on anchored parts
That’s not true. Touched events do fire for unanchored and anchored parts
Couldn’t you just use raycasts?? They don’t create any lag and are very performant so also don’t take up a lot of memory
1 Like
Hm I never really thought of that as an alternative. I don’t know much about ray casting so I’ll look up some tutorials on how it works and I’ll come back if it works
1 Like
after some tweaking and editing the script abit, i’ve come up with this. It doesn’t work much and is very inconsistent. It will occasionally work but will just instantly teleport to the position and sometimes even teleport under the baseplate for some reason.
Here’s the code now
local mod = require(game.ReplicatedStorage.Modules.EffectMod)
local TS = game:GetService("TweenService")
local part = script.Parent
local Flying = false
local CreatingSphere = false
local Landed = false
local ForwardMovement = part.CFrame.LookVector * 0.5
local DownwardMovement = Vector3.new(0,-1,0)
local MovementSpeed = .1
local function CreateSphere()
--unrelated
end
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if Flying == false then
--unrelated
end
elseif hit:IsA("Part") or hit:IsA("Model") then
if Flying == true then
Flying = false
part.Anchored = false
CreateSphere()
print("Part touched")
end
end
end)
part:GetPropertyChangedSignal("Parent"):Connect(function()
if part.Parent:IsA("Folder") and (part.Parent.Name == "Aether" or part.Parent.Name == "Folder") then
CreateSphere()
local rayOrigin = part.Position
local rayDirection = part.CFrame.LookVector + Vector3.new(0,-100,0)
local params = RaycastParams.new()
params.FilterDescendantsInstances = {script.Parent}
params.FilterType = Enum.RaycastFilterType.Exclude
params.IgnoreWater = true
local Result = workspace:Raycast(rayOrigin, rayDirection)
if Result then
print("Position: "..tostring(Result.Position)..", Acceleration: "..tonumber(Result.Distance*MovementSpeed))
end
part.Anchored = true
part.Position = part.Position:Lerp(Result.Position, Result.Distance * MovementSpeed)
task.wait(MovementSpeed)
part.Anchored = false
Flying = false
end
end)
Couldn’t you just do
local rayOrigin = part.Position
local rayDirection = (part.Position - part.Position.Size.Y/2) - Vector3.new(0,1,0)
local params = RaycastParams.new()
params.FilterDescendantsInstances = {script.Parent}
params.FilterType = Enum.RaycastFilterType.Exclude
params.IgnoreWater = true
local Result = workspace:Raycast(rayOrigin, rayDirection)
if Result then
--stop the flying
end
Hold on a second, I think I know the issue!
Here’s some things you could do to fix this issue;
-Make a part that when that part touches the other part, it activates that certain script (May need edits)
-Try asking a programmer for a solution
If your reply is not going to be nice, don’t reply at all!
Do you mean like a hitbox? If so that could work but would be heavily unoptimized.
So genuine question. How would I be able to grab the position then slowly ease the part to that position.