I’m trying to make a plane/airdrop system for a last to leave the circle event for someone, but this plane thing is paaainful.
I’m trying to make a script that chooses a coordinate on a certain area then make the plane aim towards that part and go forward continuously.
CallPlane() is the function I’m having trouble with
minX, maxX, minY, maxY is the possible coordinate plane
I added comments in the CallPlane() area to understand what I did
Here is an Animation of what I’m trying to make
External Medialocal ServerStorage = game:GetService("ServerStorage")
local CollectionService = game:GetService("CollectionService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local Crate = ReplicatedStorage.RoundsItems.Airdrop.Crate
local Plane = ReplicatedStorage.RoundsItems.Airdrop.Plane
local minX = -171.174
local maxX = 171.174
local minY = -168.055
local maxY = 168.055
local module = {
Text = "Airdrop",
SubText = "Look to the sky",
Name = "airdrop",
Running = false
}
local function Callplane(startPos)
local planeClone = Plane:Clone()
planeClone.Position = Plane.Position
planeClone.Parent = workspace
local endPos = Vector3.new(startPos.X, 206, startPos.Z) -- Position to fly towards
local direction = (endPos - startPos).unit -- Calculate the direction
RunService.Heartbeat:Connect(function(deltaTime)
local newPos = planeClone.Position + direction * 50 * deltaTime -- Speed of the plane
planeClone.Position = Vector3.new(newPos.X, 0, newPos.Z) -- Only update X and Z, keeping Y constant
-- Check if the plane is close to the destination
if (Vector2.new(newPos.X, newPos.Z) - Vector2.new(endPos.X, endPos.Z)).magnitude < 5 then
planeClone:Destroy() -- Destroy the plane
end
end)
end
local function DropCrate(cratePosition)
local crateSize = Vector3.new(10, 10, 10)
local crateClone = Instance.new("Part")
crateClone.Size = crateSize
crateClone.Position = cratePosition
crateClone.Anchored = true
crateClone.Parent = workspace
end
local function Clear()
local plane = workspace:FindFirstChild("Plane")
local crate = workspace:FindFirstChild("Crate")
if plane then
plane:Destroy()
end
if crate then
crate:Destroy()
end
end
local function Main()
local startPos = Vector3.new(math.random(minX, maxX), 205, math.random(minY, maxY))
Callplane(startPos)
DropCrate(startPos)
end
function module:Start()
if self.Running then
self:Stop()
end
self.Running = true
Main()
end
function module:Stop()
if not self.Running then return end
self.Running = false
Clear()
end
return module
I’ve searched miles through the developer hub to find something that could help me but I’ve had no luck, so here I am.