Transferring BodyGyro and BodyPosition functionality to physics constraints

Hello, I am currently trying to rotate a part in the opposite direction as its angular velocity in preparation for a ship script. I can do this easily with the legacy BodyMovers, but wish to use physics constraints as recommended by ROBLOX.

My issue isn’t an issue per se, as I have discovered a way to replicate BodyGyro CFraming with attachments and AlignOrientation; this being using an anchored part with an attachment connected to the main part’s AlignOrientation that is CFramed at will. However, I am not sure if this is the best or correct method of doing so and am asking if there are better ways of going about this. I do have a secondary issue, that being that I am unable to effectively replicate using BodyPosition to keep a part at a set y-value. AlignPosition doesn’t seem to be able to be only exerted on one axis and thus I have been using a VectorForce equal to the ROBLOX weight force. However, this means that if the part’s look vector is facing upward, the part will move in this direction as it is not forced to a set y-value.

My explanation may be a bit confusing, so here’s what’s happening (left is with physics constraints, right is with legacy movers and the desired result for physics constraints).

https://gyazo.com/3becfb0cfc643beb7a72111b22eb28c3

Additionally, here are the objects and scripts used for each part.

https://gyazo.com/001a23c0001c4923ee5fa83037743a68.png

local m = script.Parent:GetMass()

script.Parent["Anti-Gravity"].Force = Vector3.new(0,workspace.Gravity * m, 0)
script.Parent.AlignOrientation.Attachment1.CFrame = script.Parent.AlignOrientation.Attachment1.CFrame * CFrame.Angles(0,0,math.rad(-45))

game:GetService("RunService").Heartbeat:Connect(function()
	script.Parent.Velocity = script.Parent.CFrame.LookVector * 5
end)

https://gyazo.com/fc3e9fa884300afe0e5ffee4be0873e5.png

game:GetService("RunService").Heartbeat:Connect(function()	
	local Guide = script.Parent.CFrame * CFrame.new(-1, 0, 0)
	script.Parent.BodyGyro.CFrame = CFrame.new(script.Parent.Position, Vector3.new(Guide.X, script.Parent.CFrame.Y + 0.6, Guide.Z))
	script.Parent.BodyVelocity.Velocity = script.Parent.CFrame.LookVector * 5
end)

Both scripts use arbitrary constants, e.g. a multiplier of 5 for the velocity, as I’m just trying to get the idea of how the scripting would work.

In conclusion, my question is how would I maintain a set y-level with physics constraints and is there a better way of using AlignOrientation? This is my first time using this forum so I apologise if this thread is not as clear as it could be.

EDIT: current properties of physics constraints.

1 Like

Not that familiar with constraints but from a quick look I think I need to see what you have setup for the constraints in the explorer as they don’t appear in your script.

Alright, added properties to the bottom of the main post.

Thanks for doing that.
I am now wondering if instead of running at Heartbeat you run it stepped with a delay of a few seconds to see what the changes are to the positions, orientation, rotation of the two objects.
You could add prints into the heartbeat version but I think the output would be too fast.