generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Plane Wing movement(Prize If solved)

Previous Thread :: Next Thread 
Maker50001 is not online. Maker50001
Joined: 22 Nov 2014
Total Posts: 64
30 Dec 2014 03:37 PM
local players = game:GetService("Players")
local player = players.LocalPlayer
local cam = game.Workspace.CurrentCamera
local plane = script.Plane.Value
script.Plane:Destroy()
local gui = script.PlaneGui:Clone()
script.PlaneGui:Destroy()

local health = plane.Health
local maxHealth = math.abs(health.Max.Value)
if (maxHealth == 0) then maxHealth = 1 end
local dead = false

local mouse = player:GetMouse()
local custom = plane.Customize

local maxThrust = 0
local thruster,gyro

local doPushback = false


-- Small optimization help:
local CFNEW = CFrame.new
local CFANG = CFrame.Angles
local V3NEW = Vector3.new
local RAD = math.rad
local FLOOR = math.floor



-- Operationals
local op = (function()
local o = plane.Operational
local t = {
seat = o.MainSeat;
landingGear = o.LandingGear;
main = o.Main;
flying = true;
flyingStopped = false;
}
return t
end)();



-- Load customized plane properties:
local properties = {
maxSpeed = custom.MaxSpeed.Value;
desiredSpeed = 0; -- Actual speed of the plane; manipulated by throttle input
spdIncRate = custom.MaxSpeed.IncreaseRate.Value;
autoLandingGear = custom.AutoLandingGear.Value;
fadeLandingGear = custom.FadeLandingGear.Value;
groupSpecific = {custom.GroupSpecific.Value,custom.GroupSpecific.GroupID.Value};
planeName = custom.PlaneName.Value;
teamSpecific = {custom.TeamSpecific.Value,custom.TeamSpecific.TeamColor.Value};
thrustRatio = custom.ThrustRatio.Value;
decPrec = custom.DecimalPrecision.Value;
maxBank = custom.MaxBank.Value;
pushback = custom.Pushback.Value;
pushbackSpeed = math.abs(custom.Pushback.Speed.Value);
canCrash = custom.CanCrash.Value;
lockCam = custom.LockCamera.Value;
bankSensitivity = (function()
local s = custom.BankSensitivity.Value
s = (s < 0 and 0 or s > 10 and 10 or s)
s = ((10-s)/10)
return (500+(2.5e3*s))
end)();
}



-- Throttle control:
local throttle = {
cur = 0;
rate = 0.02;
up = false;
dn = false;
bar = gui.Panel.Throttle.Bar;
perc = gui.Panel.Throttle.Percent;
update = function(self)
if (self.dn or self.up) then
if (self.up) then self.cur = (self.cur+self.rate) end
if (self.dn) then self.cur = (self.cur-self.rate) end
self.cur = (self.cur < 0 and 0 or self.cur > 1 and 1 or self.cur)
self.bar.Size = UDim2.new(self.cur,0,1,0)
self.perc.Text = (tostring(FLOOR(self.cur*100)) .. "%")
if (self.cur > 0) then EndPushback() end
end
end;
}


-- Like FindFirstChild, but it will create the object if it does not exist
function FindOrCreate(parent,name,class,createFunc)
local x = parent:FindFirstChild(name)
if (not x) then
x = Instance.new(class,parent)
x.Name = name
if (createFunc) then createFunc(x) end
end
return x
end



ToggleLandingGear,IsLandingGearDown = (function()
local lg = op.landingGear
local f = properties.fadeLandingGear
local down = true
local active = false
local all = {}
local function Scan(p)
for _,o in pairs(p:GetChildren()) do
if (o:IsA("BasePart")) then table.insert(all,o) end
Scan(o)
end
end
Scan(lg)
local function Fade(start,stop,step)
for i = start,stop,step do
for _,v in pairs(all) do v.Transparency = i end
wait(1/30)
end
end
return function()
if (active) then return end
Delay(0,function()
active = true
down = (not down)
if (down) then
if (f) then Fade(1,0,-0.2) end
for _,v in pairs(all) do
v.CanCollide = true
v.Transparency = 0
end
else
EndPushback()
if (f) then Fade(0,1,0.2) end
for _,v in pairs(all) do
v.CanCollide = false
v.Transparency = 1
end
end
active = false
end)
end,
function()
return down
end
end)();



TogglePushback,EndPushback = (function()
local pushing = false
return function()
if (pushing) then
pushing = false
elseif (throttle.cur <= 0 and op.main.Velocity.magnitude <= 6 and IsLandingGearDown()) then
pushing = true
end
doPushback = pushing
end,
function()
pushing,doPushback = false,false
end
end)();



function MouseDown()
-- Left click down
end

function MouseUp()
-- Left click up
end

function KeyDown(k)
if (k == "w" or k:byte() == 17) then
throttle.up = (true and not dead)
elseif (k == "s" or k:byte() == 18) then
throttle.dn = (true and not dead)
elseif (k == "g" and not properties.autoLandingGear and not dead) then
ToggleLandingGear()
elseif (k == "b" and properties.pushback and not dead) then
TogglePushback()
end
end

function KeyUp(k)
if (k == "w" or k:byte() == 17) then
throttle.up = false
elseif (k == "s" or k:byte() == 18) then
throttle.dn = false
end
end


-- Triggered when Health hits 0 (only if Customize.CanCrash is 'true')
function Died()
if (dead) then return end
dead = true
throttle.up,throttle.dn = false,false
gui.Panel.Throttle.Bar.Size = UDim2.new(0,0,1,0)
gui.Panel.Throttle.Percent.Text = "0%"
EndPushback()
end


-- Update the GUI
InterfaceUpdate = (function()
local panel = gui.Panel
local alt = panel.Altitude.Amount
local spd = panel.Speed.Amount
local vspd = panel.VerticalSpeed.Amount
local last = 0
local dec = properties.decPrec
dec = (dec < 0 and 0 or dec > 3 and 3 or dec)
local formatter = ("%." .. tostring(dec) .. "f")
return function()
local t = time()
if ((t-last) < 0.1) then return end
last = t
alt.Text = formatter:format(op.main.Position.y)
spd.Text = formatter:format(op.main.Velocity.magnitude)
vspd.Text = formatter:format(op.main.Velocity.y)
end
end)();



-- Get the bank of the aircraft based on the user's mouse position on-screen (ratio relative to center-screen)
function GetBank()
local vsx,x = mouse.ViewSizeX,mouse.X -- ViewSizeX, X
local vsxH = (vsx/2.0) -- ViewSizeX Half
local r = ((vsxH-x)/vsxH)
r = (r < -1 and -1 or r > 1 and 1 or r) -- Ratio
local s = op.main.Velocity.magnitude -- Speed
if (s < 45) then
local sr = ((s-30)/45.0) -- Speed ratio
sr = (sr < 0 and 0 or sr)
r = (r*sr)
gyro.maxTorque = V3NEW(maxThrust*sr,maxThrust,maxThrust*sr)
else
gyro.maxTorque = V3NEW(maxThrust,maxThrust,maxThrust)
end
return RAD(r*properties.maxBank)
end



-- Calculate what the speed of the aircraft should actually be (inputted into BodyVelocity object of the plane)
CalcDesiredSpeed = (function()
local r = properties.spdIncRate;
return function()
local s,ds = (properties.maxSpeed*throttle.cur),properties.desiredSpeed
ds = (s > ds and (ds+r) or s < ds and (ds-r) or ds)
properties.desiredSpeed = ds
end
end)();



-- Update main flight controls (thrusting, direction, and speed calculations)
function FlyUpdate()
CalcDesiredSpeed()
local r = (properties.desiredSpeed/properties.maxSpeed)
local f = (maxThrust*r)
thruster.maxForce = V3NEW(f,f*(op.main.Velocity.magnitude/properties.maxSpeed),f)
thruster.velocity = (op.main.CFrame.lookVector*properties.desiredSpeed)
if (not dead) then
if (op.main.Velocity.magnitude > 2) then
gyro.cframe = CFNEW(op.main.CFrame.p,mouse.Hit.p)*CFANG(0,0,GetBank())
end
if (doPushback) then
thruster.maxForce = V3NEW(properties.mass*100,0,properties.mass*100)
thruster.velocity = (op.main.CFrame.lookVector*-properties.pushbackSpeed)
end
end
end



-- Check to see if the plane is near the ground
function NearGround()
local ray = Ray.new(op.main.Position,V3NEW(0,-50,0))
local hit,pos = game.Workspace:FindPartOnRay(ray,player.Character,true)
return (hit and true or false)
end



-- Main update loop of the plane (executes about every 0.03 seconds)
Update = (function()
local autoLg = properties.autoLandingGear
local lastAuto = 0
return function()
FlyUpdate()
InterfaceUpdate()
throttle:update()
if (autoLg) then
local t = time()
if ((t-lastAuto) > 0.5) then
lastAuto = t
local down = IsLandingGearDown()
local near = NearGround()
if ((near and not down) or (not near and down)) then ToggleLandingGear() end
end
end
end
end)();



-- First function called. This is basically the "start up" of the plane
function Setup()

-- Hardware control event setup:
mouse.Button1Down:connect(MouseDown)
mouse.Button1Up:connect(MouseUp)
mouse.KeyDown:connect(KeyDown)
mouse.KeyUp:connect(KeyUp)

cam.CameraType = Enum.CameraType[(properties.lockCam and "Attach" or "Follow")]

gui.Panel.PlaneName.Text = properties.planeName
gui.Panel.Visible = false
gui.Parent = player.PlayerGui

-- Find or create movement objects:
GetPlaneMass()
GetMaxThrust()
thruster = FindOrCreate(op.main,"Thruster","BodyVelocity")
thruster.maxForce = V3NEW()
thruster.velocity = V3NEW()
gyro = FindOrCreate(op.main,"Gyro","BodyGyro",function(o)
o.cframe = CFNEW(op.main.Position,(op.main.Position+op.main.CFrame.lookVector))
o.D = properties.bankSensitivity
wait(1)
o.maxTorque = V3NEW(maxThrust,maxThrust,maxThrust)
end)

-- Health setup:
local hBar,hTitle = gui.Panel.Health.Bar,gui.Panel.HealthTitle
hTitle.Visible,gui.Panel.Health.Visible = properties.canCrash,properties.canCrash
if (properties.canCrash) then
local p = gui.Panel.Health.Percent
hBar.Size = UDim2.new((health.Value/maxHealth),0,1,0)
p.Text = (tostring(FLOOR((health.Value/maxHealth)*100)) .. "%")
gui.Panel.Size = UDim2.new(0,200,0,130)
health.Changed:connect(function(h)
if (h < 0) then h = 0 end
local r = (h/maxHealth)
hBar.Size = UDim2.new(r,0,1,0)
p.Text = (tostring(FLOOR(r*100)) .. "%")
if (h == 0 and not dead) then Died() end
end)
end

gui.Panel.Visible = true


-- Core flight loop
local w = (1/30)
while (op.flying and not dead) do
Update()
wait(w)
end
throttle.cur = 0
while (op.flying and health.Value > -50) do
Update()
gyro.cframe = (gyro.cframe*CFANG(0,0,RAD(4)))
wait(w)
end
op.flyingStopped = true


end



-- Get the mass of the plane
function GetPlaneMass()
if (properties.mass) then return properties.mass end
local m = 0
local function Scan(p)
for _,o in pairs(p:GetChildren()) do
if (o:IsA("BasePart")) then m = (m+o:GetMass()) end
Scan(o)
end
end
Scan(plane)
properties.mass = m
return m
end


-- Set the max thrust (function name 'Get' a bit misleading)
function GetMaxThrust()
maxThrust = ((properties.mass*(236/1.2))*properties.thrustRatio)
end


-- Called when the user exits the plane
function ForceRemove()
op.flying = false
gui:Destroy()
cam.CameraType = Enum.CameraType.Custom
while (not op.flyingStopped) do wait() end
if (gyro and gyro.Parent) then gyro:Destroy() end
if (thruster and thruster.Parent) then thruster:Destroy() end
script.ForceRemove.Ready.Value = true
end

local fr = script.ForceRemove
if (fr.Value) then ForceRemove() else
local con
con = fr.Changed:connect(function(v)
if (v) then
con:disconnect()
ForceRemove()
end
end)
end
Setup()

function wingani()
local mouse = player:GetMouse()

function CalculateOffset()
local offset = {}
offset.X = mouse.X - mouse.ViewSizeX/2
offset.Y = mouse.Y - mouse.ViewSizeY/2
end

while true do wait()
local offset = CalculateOffset()
end

CalculateOffset()

end

How would incorperate the movements based on the offsets on the screen
w.C0=CFrame.new(0,0,2)*CFrame.Angles(0,0,0)
w.C1=CFrame.Angles(0,math.rad(0),0)

whoever gets this will get 250 robux
post a link to a shirt for 250robux
along with the finished version of the script
the Left Aileron and Right Aileron should move when the mouse moved either left or right
i'm also willing to increase the prize

Report Abuse
crazyman32 is not online. crazyman32
Joined: 13 Apr 2008
Total Posts: 18027
30 Dec 2014 03:44 PM
My goodness, is that my old code I see?

That code was not written to handle animations, so implementing them will be difficult.
Report Abuse
Fedorakid is not online. Fedorakid
Joined: 17 Jul 2010
Total Posts: 7079
30 Dec 2014 03:46 PM
HAHA!

I love it when crazyman does that, every time I see "plane" or something related on roblox I think "crazyman32" because you are the plane guy of roblox. (and you know it hehe)
Report Abuse
iiEssence is not online. iiEssence
Joined: 18 Jun 2014
Total Posts: 3467
30 Dec 2014 03:46 PM
busted
Report Abuse
Maker50001 is not online. Maker50001
Joined: 22 Nov 2014
Total Posts: 64
30 Dec 2014 03:50 PM
So would you recommend writing a separate script or do you have something that you could donate for my cause?
Report Abuse
crazyman32 is not online. crazyman32
Joined: 13 Apr 2008
Total Posts: 18027
30 Dec 2014 03:52 PM
Well, the problem is that animating the plane would mean that you would need to rewrite the auto-weld script.

In order to animate parts on a plane, you need to create special welds to handle the animated parts. To do that, you have to create "joint" parts that serve as the connection between the animated part and the static plane.

It's quite a complicated process.

I've been wanting to write a plugin to streamline the process, but I haven't yet.
Report Abuse
Maker50001 is not online. Maker50001
Joined: 22 Nov 2014
Total Posts: 64
30 Dec 2014 03:53 PM
Do you have old code that you can send me a link to or email to me?

My dream is to create great planes on Roblox like you did
Report Abuse
Maker50001 is not online. Maker50001
Joined: 22 Nov 2014
Total Posts: 64
30 Dec 2014 04:00 PM
Also what about the Code you used in this old vid

https://www.youtube.com/watch?v=u405SX33IwM

do you think you could make any of your old creations of yours available to me so that i can learn?
Report Abuse
Maker50001 is not online. Maker50001
Joined: 22 Nov 2014
Total Posts: 64
30 Dec 2014 04:04 PM
bump
Report Abuse
Maker50001 is not online. Maker50001
Joined: 22 Nov 2014
Total Posts: 64
30 Dec 2014 04:51 PM
Bump
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image