Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

How to apply a force to an anchored part?

Asked by
Ribasu 127
6 years ago

I have a part spinning with the use of a BodyAngularVelocity. However, I need such an action to be performed while the part is in the air, not while hitting the baseplate, so I am anchoring it when it is in the air- but this breaks the force, the part stops spinning while anchored. How can I exert a force on an anchored object, or exert a force which leaves my part spinning in the air in the position I specify?

2 answers

Log in to vote
2
Answered by
fredfishy 833 Moderation Voter
6 years ago

You could try a BodyPosition, which continually applies force to an object to move it back to a specified position.

function makeHover(part)
    local bodyPosition = Instance.new("BodyPosition", part)
    bodyPosition.Position = part.Position
end

Alternatively, you could counteract the forces of gravity with a BodyForce.

function makeHover(part)
    local bodyForce = Instance.new("BodyForce", part)
    bodyForce.Force = Vector3.new(0, part:GetMass() * workspace.Gravity, 0)
end

Finally, you could keep the part anchored, but use CFrame to rotate it gradually.

function makeHover(part)
    for i = 0, math.pi * 2, math.pi / 64 do
        part.CFrame = part.CFrame * CFrame.Angles(0, math.pi / 64, 0)
        wait(0.2)
    end
end
Ad
Log in to vote
1
Answered by 6 years ago

You cannot exert a force on an anchored part, as it is completely exempt from physics when anchored. In order to keep it in the air, look into BodyPosition or BodyForce, as these can help keep your object in the air. BodyPosition allows you to specify a position for your object to go to and stay at, while BodyForce acts as a constant force for/against/neutral to gravity.

Answer this question