So, I’m trying to make a spaceship game, and I’m working with physics in order to move my spaceship. yet, for example, I try to keep the ship up in the air without needing to anchor any part. The idea behind this is that when the player enters the model, a strong force pushes the model up in the air, where after a few seconds this stabilising force kicks in. Yet, anything I’ve tried failed. I alr looked at many, many codes online, and I even studied these calculations at school, so I’m sure they’re not wrong. Heck, I tried to put the force to infinite and my model still refuses to move an inch.
return function(BasePartsChildren)
for _, Part in pairs(BasePartsChildren) do
Part:ApplyImpulse(Vector3.yAxis*Part.AssemblyMass*20)
end
end
This is the code I use to launch my model up in the air, it does it job well
(small screenshot of the ship being in the air for less than a second, but I can change the 20 to a much higher number and it’ll, logically, jump much higher)
Yet as soon as it comes to add the stabilising force…
Nothing, even tho as you can see in the properties, there is a strong force in place, but the ship falls down as if the force didn’t exist. Heck, I tried to strengthen the force by a lot (as you can see in the screenshot, the numbers are ridiculous), even once with infinity, and it still won’t budge. Does anyone also have problems when it comes to apply vectorforces to models?
are there other scripts modifying your ship in any way?
from what i remember, vectorforce should be parented to an Attachment
also, try this script and let me know if any of these work or if you get no satisfactory results
(BTW, I also recommend using print() to clear your suspicions)
local RunService = game:GetService("RunService")
local function applyForce(BasePartsChildren)
local gravity = Vector3.new(0, -196.2, 0)
RunService.Heartbeat:Connect(function()
for _, Part in pairs(BasePartsChildren) do
local force = -gravity * Part.AssemblyMass
Part:ApplyImpulse(force)
end
end)
end
Thanks! I can’t believe that the solution was this simple, and yet took me days and a post on the forum to figure it out:
seat:GetPropertyChangedSignal("Occupant"):Connect(function() --If the player sits down or leaves
local occupant = seat.Occupant
local hoverForce = SSS_Script.hoverForce.Value :: VectorForce
if not hoverForce then --I only need to check one, since the other one will automatically be set as well
local seatAttachment = Instance.new("Attachment") --Setting all the attachments
seatAttachment.Name = "seatAttachment"
seatAttachment.Parent = seat --I forgot this little, little, tiny line, lmao
local hoverAttachment = Instance.new("Attachment")
local newHoverForce = Instance.new("VectorForce")
local orientation, size = seat.Parent:GetBoundingBox()
newHoverForce.Name = "hoverForce"
newHoverForce.Parent = seat
newHoverForce.ApplyAtCenterOfMass = true
newHoverForce.Enabled = true
hoverAttachment.Name = "hoverAttachment"
hoverAttachment.Parent = seat
hoverAttachment.WorldCFrame = orientation*CFrame.new(0, -size.Y/2, 0)
seatAttachment.WorldCFrame = orientation
newHoverForce.Attachment0 = seatAttachment
newHoverForce.RelativeTo = Enum.ActuatorRelativeTo.World
hoverForce = newHoverForce
end
--rest of code: [...]
end
When you said that VF needs an attachment, I was sure that it couldn’t be the problem, since I already knew about it and had taken it into account, but nope, I forgot to actually give the attachment a parent on its own xD (basically, my own code is a mess and I have to work on it)
thanks a lot for your help tho, I’m sure some people in the future might make use of your code snippet!
Cheers!