I'm trying to make the landing sequence more automatic for some StarWars starfighters I've been working on. Until recently I've used a short for loop to make the fighter descend for several seconds before shutting off the "engines," but if you land from too close or too high from the ground, you'll either glitch into the ground or bounce a few times. Therefore I thought to use a repeat until SomePart.Touched loop to descend until a "landing gear" part touched another part. But... there never seems to be a time when Touched is nil or false, so the fighter just drops. I tried this, but the same thing happens:
--RayCast function to detect when another part is close
function near(start, oclu)
local ray = Ray.new(start.Position, Vector3.new(0,-4,0))
local hit, pos = game.Workspace:FindPartOnRay(ray, Plane)
if hit and pos and (start.Position - pos).magnitude < 5 then
return true
end
return nil
end
--Repeat loop that uses the above function
--Plane is defined earlier, don't worry
local forc = Plane.Parts.Engine.BodyVelocity
local dam = Plane.Parts.Damage
forc.maxForce = Vector3.new(math.huge, math.huge, math.huge)
repeat
forc.velocity = forc.velocity + Vector3.new(0, -2, 0)
wait(0.1)
until near(dam, Plane.Parent) == true
wait()
forc.velocity = Vector3.new(0, 0, 0)
forc.maxForce = Vector3.new(0, 0, 0)
I don't know if I'm simply missing something that would make the Touched and RayCast checks always be true, or what, so feel free to suggest whichever you think is more efficient.
