I need to attach non-cancollide part near the bottom a ball that will be rolling. I don’t want this part to change orientation with the ball, but I do want the part to stay with the ball at all times as it moves around, position wise. The part cannot affect the balls rolling physics in any way.
I am not sure I am using this right. When I attach the non-cancollide part at the bottom of the ball, and the other attachment in the center of the ball, it just spins the non-cancollide part around the ball as it rolls.
Solution that avoids AlignPos/Orientation, as well as BodyPos/Gyro.
I would use an extra proxy part to attach the ball and non-cancollide part.
Here’s how:
Make the proxy part invisible and turn CanCollide off for the proxy part. Set it’s Massless property to True. Position the proxy at the center of the Ball.
Create a Ball Socket attachment between the proxy and the ball. Then, change Attachment0 and Attachment1 to both have CFrame.new() as their CFrame. Lastly, change the BallSocketConstraint Radius to 0. This allows the ball to freely rotate around the proxy without influencing it’s orientation.
Set your non-cancollide part to also have Massless = true. Then, simply create a weld attachment between your non-cancollide part and the proxy and you’re done.
If you want to script it yourself, you could essentially do something like this:
local BallPart, ConstantPart
BallPart:GetPropertyChangedSignal("Position"):Connect(function()
local Position = BallPart.Position
ConstantPart.CFrame = CFrame.new(Position.X, Position.Y, Position.Z)
end)
This should work AFAIK but if it doesn’t have a look at the CFrame.new() constructor’s documentation (and the properties for CFrame) to add in the rotation values.
The non-cancollide part just spins around the ball, even if the ball isn’t moving.
EDIT: After changing my balls position with a script, the non-cancollide part gets lost for a few seconds, only before it reattaches to the ball in a weird way. I am not sure attachments are the way to go because of this.
Here is an example in Studio.
If you wanted some code to do all of this automatically, I think this should do it.
This only needs to be run once to set everything up. From there, you can delete the script as there is no requirement for a loop which constantly sets the Part’s position. The attachments should do the rest.
local Ball = game.Workspace.Ball
local Part = game.Workspace.Part
local Proxy = Instance.new("Part")
Proxy.Parent, Proxy.Name = game.Workspace, "Proxy"
Proxy.Size = Vector3.new(1, 1, 1)
Proxy.CanCollide, Proxy.Massless = false, true
Proxy.Transparency = 1
Proxy.CFrame = CFrame.new(Ball.Position)
local Attachment0 = Instance.new("Attachment")
Attachment1 = Attachment0:Clone()
Attachment0.Parent, Attachment1.Parent = Proxy, Ball
local BallSocket = Instance.new("BallSocketConstraint")
BallSocket.Parent, BallSocket.Radius = Proxy, 0
BallSocket.Attachment0, BallSocket.Attachment1 = Attachment0, Attachment1
Part.CanCollide, Part.Massless = false, true
local WeldAttachment = Instance.new("WeldConstraint")
WeldAttachment.Parent = Proxy
WeldAttachment.Part0, WeldAttachment.Part1 = Proxy, Part
I discovered the problem only occurs when the position of the ball is changed via script. Your way works well otherwise. Do you know a way to keep everything together if the position is changed?
When re-positioning the ball by script, make sure you also re-position the proxy part and the non-cancollide part with the ball. I.e. Proxy should always have the same position as the ball position and the non-cancollide part should always be the same vector off. Otherwise, they snap to one another and a rotary force occurs on the proxy causing everything to spin.
Alternatively and much more simply, I suppose you could just insert a BodyGyro into the proxy part with MaxForce inf, inf, inf. That way, it is prevented from rotating.