# Having Problems with VectorForce

So I want to make a flying broom like in harry potter. So I already made one and it works very well, there is just one bug and it is that the broom can fly through objects. That is because I am always changing the CFrame and that is the reason why it can’t go through objects.

I tried making a flying broom with alignrotation and vectorforce, but the vectorforce behaves really weird. My broom doesn’t fly up, even if I put a high force, it still doesn’t fly up and it gets really fast. If you know a better solution than using vectorforce, please tell me.

Hirarchy:

Video:

If you also want the script please tell me.

I would like an example of the `VectorForce` properties during flight to know exactly what’s happening.

Do you need this?

The force of gravity is probably negating any upwards force applied by the VectorForce. The default gravity is ~192 studs/s^2, and if you were aiming straight up giving a force of (0, 2000, 0) then that would be completely negated by a mass of just 10.5 mass units.

The best solution is probably to take gravity completely out of the picture while the broom is supposed to be in control. There’s no built in way to do this for just one player a time, but you can accomplish it by applying an upwards force that completely negates gravity. Something like this should work:

``````function disableModelGravity(model)
for _, part in ipairs(getModelParts(model)) do
disablePartGravity(part)
end
end

function enableModelGravity(model)
for _, part in ipairs(getModelParts(model)) do
enablePartGravity(part)
end
end

function disablePartGravity(part)
enablePartGravity(part)

local force = Instance.new("BodyForce")
force.Force = Vector3.yAxis * part:GetMass() * workspace.Gravity
force.Name = "AntiGravityForce"
force.Parent = part
end

function enablePartGravity(part)
local force = part:FindFirstChild("AntiGravityForce")
if force then
force:Destroy()
end
end

function getModelParts(model)
local parts = {}
for _, d in ipairs(model:GetDescendants()) do
if d:IsA("BasePart") then
table.insert(parts, d)
end
end
return parts
end
``````

Just call `disablePartGravity` on the broom and character when the player gets on the broom, and `enablePartGravity` when they get off the broom.

So I tried using your script. It eliminates Gravity but it is still very skechy:

What I am trying to do is fix this problem:

I want the broom the work exactly like this one that uses CFrames to move it. But like I said it can go through objects.

If you want it to work like the one that uses `.CFrame` you should try using an `AlignPosition` instead of a `VectorForce`.

And how should I use alignposition? With which object’s position should I align with what?

Edited to fix misplaced words.

You could simply set the `AlignPosition`'s `.Mode` to `Enum.PositionAlignmentMode.OneAttachment`, `.Attachment0` to an attachment inside of the broom part and set the `.Position` to the position of the CFrame you use for the broom that uses CFrame.

Also set `.MaxForce` and `.MaxVelocity` to `math.huge`.

The anti-gravity did not work, because well first of all the player still has mass and the broom. You have to apply both with anti-gravity or apply anti-gravity on one and make the other one `Masless`.

So what I suggest doing is getting the mass of the character and broom (or make the broom `Masless` and then exclude it) then followed by using the anti-gravity force.
Oh yeah another note, try setting all parts of the player to `Masless`, same for the broom.

``````for _, descendant in pairs(character:GetChildren()) do
if descendant:IsA("BasePart") then
descendant.Massless = true
end
end
``````

This just might fix all the current problems.

I already tried making all the parts in the broom massless earlier, but it didn’t work.

Did you put anti-gravity force on ALL parts, character and broom included?

Not the character.

30_character

Then that’s the solution, as I said before in the original post

You have to apply the anti-gravity force on the broom and the character. Though in my opinion I do not really like the script @ThanksRoBama, because it uses quite a lot of functions. Instead I would personally use something like this:

``````local function toggleModelGravity (model, state)
-- if state is on then anti-grav gets turned on
for _, descendant in pairs(model:GetDescendants()) do
-- loop through all descendants of the model
if descendant:IsA("BasePart") then
-- verify that it is a part
local force = descendant:FindFirstChild("AntiGravityForce") or Instance.new("BodyForce")
-- get the previous AntiGravForce, or make a new one
if state then
-- set properties
force.Force = Vector3.yAxis * descendant:GetMass() * workspace.Gravity
force.Name = "AntiGravityForce"
force.Parent = descendant
-- else destroy
else force:Destroy() end
end
end
``````

Then just apply it to the character and the broom

``````toggleModelGravity(player.Character, true)
toggleModelGravity(broom, true)
``````
1 Like

I am having a little trouble setting up the alignposition.

here are the properties

The attachment is in the middle of the broom

and this is the script (not the entire one)

``````script.Parent.AlignPosition.Position = script.Parent.Position
if Holding_W == true then
script.Parent.AlignPOSITIONAttachment.CFrame = script.Parent.AlignPOSITIONAttachment.CFrame + script.Parent.FakeBroom.LookVector * speed
end
``````

and here is the hirarchy again

1 Like

It gives me this tiny error right here:

did you mean to put model in there or something else?

1 Like

Right my bad, replace ‘part’ with descendant.
I edited the script with the fixed version.