How do I make my space ship hover and move?

EDIT: solved, just removed the script where it made every objects mass to 0. this solved the issue where if i walked into a wall, it would fling at mach 10million.

hello, ive been trying to get my space ship to fly for a while.

  1. What do you want to achieve?
    i want to make my space ship full of mesh parts fly (or anything really). i want it to be able to hover in the air, change altitude by pressing e/q and be able to move around

  2. What is the issue?
    i dont know where to start. ive heard of BodyGyro but im pretty sure thats depricated. ive also tried going on chatgpt, but the ai model gets all the scripts messed up

  3. What solutions have you tried so far?
    ive scavenged the internet and found this video, but if i try to insert other parts and weld them together, it doesnt do anything

2 Likes

first if your ship contains many part or mesh you need to weld them to one part (make a part and weld all the parts and meshs of your ship to the part then name the part something like “RootPart” and make it transparent by setting the Transparency property to 1 after that you should have the ship moving with the part , BodyGyro is deprecated so you should use something like VectorForce or LinearVelocity to keep the ship flying , use UserInputService to trigger when the player press a certain key “Note UserInputService need to be used in a local script so it runs on the client to detect the client inputs”

1 Like

thanks for your reply. i kind of got it working, i can move the space ship around using the U,J,H,K keys but when my player stands on the ship, it just disappears. (it flings super fast out of the map)

heres my script:

Script
local primaryPart = script.Parent:WaitForChild("PrimaryPart")

for _, part in ipairs(script.Parent:GetDescendants()) do
	if (part:IsA("BasePart") or part:IsA("MeshPart")) and part ~= primaryPart then

		-- Create a new Weld
		local weld = Instance.new("Weld")
		weld.Part0 = primaryPart
		weld.Part1 = part
		weld.C0 = primaryPart.CFrame:Inverse() -- PrimaryPart's local CFrame
		weld.C1 = part.CFrame:Inverse() -- Part's local CFrame
		weld.Parent = primaryPart
		part.Massless = true
		if part.Anchored then part.Anchored = false end
	end
end

local attachTo = Instance.new("Attachment", primaryPart)
local vectorForce = Instance.new("VectorForce")
vectorForce.Attachment0 = attachTo
vectorForce.ApplyAtCenterOfMass = true
vectorForce.Force = Vector3.new(0, workspace.Gravity * primaryPart.Mass, 0)
vectorForce.Parent = primaryPart

local bodyGyro = primaryPart:FindFirstChild("BodyGyro") or Instance.new("BodyGyro", primaryPart)
bodyGyro.MaxTorque = Vector3.new(400000, 400000, 400000)
bodyGyro.D = 5000

local bodyAngularVelocity = primaryPart:FindFirstChild("BodyAngularVelocity") or Instance.new("BodyAngularVelocity", primaryPart)
bodyAngularVelocity.MaxTorque = Vector3.new(0, math.huge, 0)
bodyAngularVelocity.AngularVelocity = Vector3.new(0, 0, 0)
bodyAngularVelocity.P = 3000

local rotationSpeed = .2
local XZVector = Vector3.new(.4,.4,.4)

local attachment = Instance.new("Attachment",primaryPart)
local dragForce = Instance.new("VectorForce")
dragForce.Name = "VectorForceDrag"
dragForce.Attachment0 = attachment
dragForce.Force = Vector3.new()
dragForce.RelativeTo = Enum.ActuatorRelativeTo.World
dragForce.Parent = primaryPart


local replicatedstorage = game:GetService("ReplicatedStorage")
local j = replicatedstorage.Remotes:WaitForChild("jPress")
local h = replicatedstorage.Remotes:WaitForChild("hPress")
local u = replicatedstorage.Remotes:WaitForChild("uPress")
local k = replicatedstorage.Remotes:WaitForChild("kPress")

u.OnServerEvent:Connect(function()
	print('received')
	local currentForce = vectorForce.Force 
	vectorForce.Force = currentForce + Vector3.new(0, 1, 0)
end)

j.OnServerEvent:Connect(function()
	local currentForce = vectorForce.Force 
	vectorForce.Force = currentForce + Vector3.new(0, -1, 0)
end)

h.OnServerEvent:Connect(function()
	print("Turning right")
	local currentForce = bodyAngularVelocity.AngularVelocity
	bodyAngularVelocity.AngularVelocity = currentForce + Vector3.new(0,rotationSpeed,0)
end)

k.OnServerEvent:Connect(function()
	print("Turning right")
	local currentForce = bodyAngularVelocity.AngularVelocity
	bodyAngularVelocity.AngularVelocity = currentForce + Vector3.new(0,-rotationSpeed,0)
end)

while task.wait() do
	local velocity = primaryPart.AssemblyLinearVelocity
	local speed = velocity.Magnitude

	--the drag force section
	if speed > 0.01 then
		dragForce.Force = -velocity.Unit*(speed^2)*XZVector
	else
		dragForce.Force = Vector3.new()
	end
end

yes i know it is sloppy, but once i get everything done and working, i will reprogram it and make it more organized.

thank you!

video:

I can give you my UFO that hovers and spins around as an example, you can mess around with it with your liking if you wanna. It even moves to a position smoothly without any scripts (AlignPosition)

sure! can you please provide me with the model?