Weld CFrame Angles, Smoothly adjusted?

What is the best way to adjust weld CFrame Angles smoothly?

I have attempted it but have not gotten anywhere, if anyone could help me out or at least point me in the right direction that’d be great.

My attempt:
repeat wait() weld.C0 = weld.C0 + CFrame.new(0,0,0) * CFrame.Angles(math.rad(1), math.rad(0), math.rad(0)) until weld.C0 == CFrame.new(.45,.5,.4) * CFrame.Angles(math.rad(35), math.rad(0), math.rad(0))

Feel free to point me to an easier method if there is one.

1 Like

What are you trying to adjust the angle between? In a Weld there are two CFrames, complete orientations, that describe the parts’ offsets from the center of the weld. For an angle to be relevant in 3D you need an axis of rotation, x, y, z, or otherwise. Are you wanting to rotate one part around the first? Or close the angle from the center of the weld to each part?

A picture of what you are trying to achieve and what you have may help.

I am trying to rotate the weld accordingly to move an entire model which is welded to player’s arm. But I don’t want to rotate it ‘instantly’, I want to to rotate smoothly until it hits it’s desired rotation. Which I tried doing in the repeat() until.

Here is what I am trying to achieve picture wise:

gunstage1

gunstage2

The gun itself is welded onto the right arm, I want to rotate the weld to where the gun is angled forward.

I see. A lot of variables still exist like what part of the gun is welded to the arm, the orientation of the part (which way is the x, y, z axis), and the orientation of the arm (I’m not familiar with the default orientation). In addition to make this transformation easier the Weld center orientation should be at the center of rotation and the z axis should be the axis of rotation (to the left of the character). You can then use the following to rotate the weapon one degree:

weld.C1 = CFrame.Angles(0, 0, math.pi/180) * weld.C1

It would help if you centered the arm part at the origin with no rotation and printed out the C0, C1, and gun handle CFrame.

This is a guess, tell me if im wrong. But cant you use tweening for a CFrame? It should be easy.

You can TweenService a weld? :face_with_raised_eyebrow:

This is an example:

local TweenService = game:GetService("TweenService")
local Tweeninfo = TweenInfo.new(2,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0)
local Weld = script.Parent
TweenService:Create(Weld,Tweeninfo,{C0 = Weld.C0*CFrame.Angles(0,math.rad(90),0)}):Play()

Hope this helps!

For some reason the tween doesn’t seem to work, have I done something wrong here?

local tweenProperties = {
	C0 = CFrame.new(.45,.5,.4) * CFrame.Angles(math.rad(35), math.rad(50), math.rad(45))
}
local tweenInfo = TweenInfo.new(
	1, -- Tween Length
	Enum.EasingStyle.Linear, -- Style
	Enum.EasingDirection.Out, -- Direction
	0, -- How many times it repeats Tween
	false, -- Reverse tween after complete
	0 -- Should it have a delay	
)
local tween = TweenService:Create(weld, tweenInfo, tweenProperties)
tween:Play()

When trying your script seen below,

local TweenService = game:GetService("TweenService")
local weld = Instance.new("Weld")
weld.Parent = game.Workspace.Part
weld.Part0 = game.Workspace.Part
weld.Part1 = game.Workspace.Part2
wait(2)
local tweenProperties = {
	C0 = CFrame.new(.45,.5,.4) * CFrame.Angles(math.rad(35), math.rad(50), math.rad(45))
}
local tweenInfo = TweenInfo.new(
	1, -- Tween Length
	Enum.EasingStyle.Linear, -- Style
	Enum.EasingDirection.Out, -- Direction
	0, -- How many times it repeats Tween
	false, -- Reverse tween after complete
	0 -- Should it have a delay	
)
local tween = TweenService:Create(weld, tweenInfo, tweenProperties)
tween:Play()

I did not run into any issues. Are your parts anchored? As welds do not work with both parts being anchored.

None of my parts are anchored. They are all welded.

Huh, That is strange. Is there any welds connected that could cause the issue?

I’m not entirely sure. I mean, my model as a whole is welded together but I feel like none of the welds interfere with each other.

If it helps, I can send you the entire server code.

I dont think this is a coding issue, but i dont mind if you want to show it. Whatever works for you.

Looks like you’re using welds, If I recall correctly, welds are meant to be replaced with WeldConstraints as they are more flexible and easier to use.

What I suggest doing is switching over to weld constraints, what you would do is CFrame or Position your model to your desired location and then add a weld constraint:

-- After you position and parent the gun:

local constraint = Instance.new("WeldConstraint")
constraint.Part0 = gunHandle
constraint.Part1 = localPlayerHand
constraint.Parent = gunHandle

WeldConstraints are easier to modify the CFrame and Position as well. For more information look here:

They provide examples of how to edit the position of the welded parts after it being welded.

EDIT: I believe weld constraints can also be tweened.

if WeldAction == 'SlopeArms' then
		local tweenProperties = {
			C0 = CFrame.new(.45,.5,.4) * CFrame.Angles(math.rad(35), math.rad(0), math.rad(0))
		}
		local tweenInfo = TweenInfo.new(
			1, -- Tween Length
			Enum.EasingStyle.Linear, -- Style
			Enum.EasingDirection.Out, -- Direction
			0, -- How many times it repeats Tween
			false, -- Reverse tween after complete
			0 -- Should it have a delay	
		)
		local tween = TweenService:Create(weld, tweenInfo, tweenProperties)
		tween:Play()
	end

Do keep in mind, I have used prints to make sure it does run through and pass the if statement.

Although I’d love to use WeldConstraints, I wasn’t too sure how to rotate the weld accordingly like a normal weld.

Im guessing here that you have got the tweenservice, so from what i see, does it actually show anything? Try adding in some print function around the code to see if it fires. Because this should work. BTW welds are not ment to be replaced with a weldconstraint. They are harder to use if you want to CFrame an object.

You just edit the cframe of the part you’re trying to weld and rotate the part however you want to:

part.CFrame = desiredCFrame*CFrame.Angles() 

It’s similar to what you are doing right now, I also suggest you read the API because it shows how to edit the cframe of a welded part in code.

Wow. I never known about this! I guess we all learn something! lol