How to Make a Plane/How to Make An Attacking Plane?
From ROBLOX Wiki
Contents |
Making One From Scratch
1) Create a model
2) Name it plane
3) In this Model, add a Model called Parts, and an invisible brick called Locator Brick (We will get to that Later)
4) In the parts section, make a part called Engine. It should have two scripts in it, an object value called Target, a Body Velocity, And a Body Gyro, name one script Fly, and you can leave the other unnamed.
5) In the script called Fly, put this:
Target=script.Parent.Target
plane=script.Parent
pos=plane.Position
viewRange=250
shootingRange=200
shoot=0
give=90
giveAct=false
leave=20
function findTarget()
players=game.Players:getChildren()
for i = 1, #players do
if players[i].Character ~=nil then
h=players[i].Character:findFirstChild("Plane")
if h==nil then h=players[i].Character:findFirstChild("Helicopter")end
if h~=nil then
dist=(h.Parts.Engine.Position - script.Parent.Position).magnitude
if dist<bestDist then
bestDist=dist
bestI=h
end
end
end
end
end
function fire()
local missile = plane.Parent.Missile:clone()
missile.CFrame = plane.CFrame * CFrame.new(0, 0, -35)
missile.RocketScript.Disabled = false
missile.Script.Disabled = false
missile.Parent = game.Workspace
end
while true do
bestDist=5000
if pos.y<0 or pos.y>600 then give=0 end
if pos.x<-2560 or pos.x>2560 then give=0 end
if pos.z<-2560 or pos.z>2560 then give=0 end
if Target.Value~=nil then --If there is a brick located follow that.
target=Target.Value
pos=target.Position
dist=(target.Position - plane.Position).magnitude
if (dist<shootingRange) and (shoot==1) then
fire()
end
give=give-1
if give<=60 and give>0 then
if giveAct==false then
findTarget()
end
end
if give<=0 then
Target.Value=nil
giveAct=true
end
end
if Target.Value==nil then --If there is no plane to attack go somewhere and find one.
if (pos-plane.Position).magnitude<20 then --go to the nex random place.
pos=Vector3.new(math.random(-750, 750), math.random(100, 600), math.random(-750,750))
end
if giveAct==false then
findTarget()
end
end
if bestI~=nil then --If there is a closest plane, find if you can see it then index it as the Target.
cPlane=bestI.Parts.Engine
dist=(cPlane.Position- plane.Position).magnitude
if dist<viewRange then
Target.Value=cPlane
bestI=nil
end
end
d=script.Parent.CFrame.lookVector --the following 3 lines make the Plane move forward.
dest=script.Parent.Position+d*10*9
script.Parent.BodyVelocity.velocity=(dest-script.Parent.Position)
dir=(CFrame.new(pos).p-script.Parent.Position).unit --direction we WANT to go
pos1=script.Parent.Position
pos2=script.Parent.Position+dir
script.Parent.BodyGyro.cframe=CFrame.new(pos1, pos2)
if giveAct==true then
leave=leave-1
if leave<=0 then
give=90
giveAct=false
leave=20
end
end
wait(.5)
shoot=1-shoot
end
In the Other Script, put this:
while true do wait(2) pos=script.Parent.Position if (script.Parent.Parent.here.Position - script.Parent.Position).magnitude>20 then script.Parent.Parent:Remove() end if pos.y<0 or pos.y>600 then script.Parent.Parent:Remove()end if pos.x<-2560 or pos.x>2560 then script.Parent.Parent:Remove() end if pos.z<-2560 or pos.z>2560 then script.Parent.Parent:Remove() end end
Getting Missles
1) Make a Brick
2) Size it up so it looks like a missile
3) Call it Missile
4) Insert two scripts
5) Call one of them RocketScript
6) Call the other one anything you want.
7) Put this in RocketScript:
r = game:service("RunService")
shaft = script.Parent
position = shaft.Position
function fly()
direction = shaft.CFrame.lookVector
position = position + 35*direction
error = position - shaft.Position
shaft.Velocity = 5*error
end
t, s = r.Stepped:wait()
d = t + 4.0 - s
while t < d do
fly()
t = r.Stepped:wait()
end
-- at max range
shaft:remove()
And this in the Other One
r = game:service("RunService")
shaft = script.Parent
position = shaft.Position
function fly()
direction = shaft.CFrame.lookVector
position = position + 35*direction
error = position - shaft.Position
shaft.Velocity = 5*error
end
function blow()
swoosh:stop()
explosion = Instance.new("Explosion")
explosion.Position = shaft.Position
explosion.BlastRadius = 30
-- find instigator tag
local creator = script.Parent:findFirstChild("creator")
if creator ~= nil then
explosion.Hit:connect(function(part, distance) onPlayerBlownUp(part, distance, creator) end)
end
explosion.Parent = game.Workspace
connection:disconnect()
wait(.1)
shaft:remove()
end
function onTouch(hit)
if hit.Name == "Building" or
hit.Name == "Safe" then
swoosh:stop()
shaft:remove()
return end
local parent = hit.Parent.Parent
local owner = shaft.Owner
if owner ~= nil then
if parent ~= nil and owner.Value ~= nil then
if parent ~= owner.Value then
local stunt = parent:FindFirstChild("Stunt")
if stunt ~= nil then
if stunt.Value ~= 1 then
blow()
end
else
blow()
end
end
end
end
end
function onPlayerBlownUp(part, distance, creator)
if part.Name == "Head" then
local humanoid = part.Parent:findFirstChild("Humanoid")
tagHumanoid(humanoid, creator)
end
end
function tagHumanoid(humanoid, creator)
if creator ~= nil then
local new_tag = creator:clone()
new_tag.Parent = humanoid
end
end
function untagHumanoid(humanoid)
if humanoid ~= nil then
local tag = humanoid:findFirstChild("creator")
if tag ~= nil then
tag.Parent = nil
end
end
end
t, s = r.Stepped:wait()
swoosh = script.Parent.Swoosh
swoosh:play()
d = t + 4.0 - s
connection = shaft.Touched:connect(onTouch)
while t < d do
fly()
t = r.Stepped:wait()
end
-- at max range
script.Parent.Explosion.PlayOnRemove = false
swoosh:stop()
shaft:remove()-- This Removes The Rocket When It Hits Something
