Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local gameGravity = game.Workspace.Gravity
- local thisVehicle = script.Parent.Parent.ShipModel:WaitForChild("ShipHull")
- local vehicleSeat = script.Parent.Parent.ShipModel:WaitForChild("VehicleSeat")
- local vehicleHull = script.Parent.Parent.ShipModel:WaitForChild("ShipHull")
- local playerVehicleControls = script.Parent:WaitForChild("PlayerVehicleControls")
- local scriptClone = nil
- local thisPlayer = nil
- local ControlEvent = nil
- local massValue = 0
- local massModifier = 0
- --//Setup Attachments
- local frontHullAttachment = Instance.new("Attachment")
- frontHullAttachment.Parent = thisVehicle
- frontHullAttachment.Name = "FrontHullAttachment"
- frontHullAttachment.Position = Vector3.new(0,-2.5,-4)
- local engineTrailAttachment0 = Instance.new("Attachment")
- engineTrailAttachment0.Parent = thisVehicle
- engineTrailAttachment0.Name = "EngineTrailAttachment0"
- engineTrailAttachment0.Position = Vector3.new(1,-3.5,4)
- local engineTrailAttachment1 = Instance.new("Attachment")
- engineTrailAttachment1.Parent = thisVehicle
- engineTrailAttachment1.Name = "EngineTrailAttachment1"
- engineTrailAttachment1.Position = Vector3.new(-1,-3.5,4)
- --// Create starting objects inside ship
- local BodyForce = Instance.new("BodyForce")
- BodyForce.Parent = script.Parent.Parent.ShipModel:WaitForChild("ShipHull")
- BodyForce.Name = "BodyForce"
- local bodyVelocity = Instance.new("BodyVelocity")
- bodyVelocity.Parent = script.Parent.Parent.ShipModel:WaitForChild("ShipHull")
- bodyVelocity.Name = "BodyVelocity"
- local bodyGyro = Instance.new("BodyGyro")
- bodyGyro.Parent = script.Parent.Parent.ShipModel:WaitForChild("ShipHull")
- bodyGyro.Name = "BodyGyro"
- local engineTrail = Instance.new("Trail")
- engineTrail.Parent = script.Parent.Parent.ShipModel:WaitForChild("ShipHull")
- engineTrail.Name = "EngineTrail"
- engineTrail.Attachment0 = engineTrailAttachment0
- engineTrail.Attachment1 = engineTrailAttachment1
- engineTrail.FaceCamera = true
- --// Main function when player sits in seat
- vehicleSeat:GetPropertyChangedSignal("Occupant"):Connect(function()
- if vehicleSeat.Occupant == nil then
- ExitShip()
- print ("out of ship")
- else
- WeldAll()
- CalculateMass()
- NegateGravity()
- SetupControls()
- print ("in ship")
- end
- end)
- --// Negate Gravity using BodyForce
- function NegateGravity()
- BodyForce.Force = Vector3.new(0, (massValue * gameGravity), 0)
- end
- --// Calculate mass of all parts and un-anchor them
- function CalculateMass()
- local massCalc = 0
- local shipParts = script.Parent.Parent.ShipModel:GetChildren()
- for i,v in pairs(shipParts) do
- if v:IsA ("BasePart") then
- v.Anchored = false
- massCalc = massCalc + v:GetMass()
- end
- end
- massCalc = massCalc + massModifier
- massValue = massCalc
- print (massValue)
- end
- --// Welder functions
- function partWeld(firstPart,secondPart)
- local Part0 = firstPart
- local Part1 = secondPart
- local weld = Instance.new("WeldConstraint")
- weld.Parent = game.Workspace
- weld.Part0 = firstPart
- weld.Part1 = secondPart
- --print ("welded " .. tostring(firstPart) .. " and " .. tostring(secondPart))
- end
- --// Welds all the parts otgether, this is not an auto-welder, you set the welds up manually below
- function WeldAll()
- partWeld(vehicleHull,vehicleSeat)
- end
- --// sets up all of the control events and related stuff
- function SetupControls()
- --get player in the seat
- thisPlayer = vehicleSeat.Occupant.Parent
- --clone the PlayerControlScript and set the data value for thisVehicle
- script.Parent.PlayerVehicleControls.Vehicle.Value = thisVehicle
- scriptClone = playerVehicleControls:Clone()
- scriptClone.Parent = thisPlayer
- scriptClone.Name = "PlayerVehicleControls"
- for i , v in pairs(thisVehicle:GetDescendants()) do
- if v:IsA("BasePart") then
- v:SetNetworkOwner(thisPlayer)
- end
- end
- end
- function ExitShip()
- BodyForce.Force = Vector3.new(0,0,0)
- bodyVelocity.MaxForce = Vector3.new(0,0,0)
- thisPlayer.PlayerVehicleControls:Destroy()
- for i , v in pairs(thisVehicle:GetDescendants()) do
- if v:IsA("BasePart") then
- v:SetNetworkOwnershipAuto()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement