How can i rotate a welded part?

I have been on a bossfight and one of the attacks is that it lunges with a sword, however i cant seem to rotate the sword, the sword is welded with a WeldConstraint to the arm.

I have tried using .Rotation and CFrame but neither seemed to work correctly, i also tried using a normal weld and a motor6d but it doesn’t achieve what i wanted.

function equipWeapon(weapon, arm) --equips the weapon and welds it to the arm
	local armPos = arm.CFrame - Vector3.new(0, 1, 0)
	local weapon = Weapons[weapon]:Clone()
	weapon.CFrame = armPos
	local weld = Instance.new("WeldConstraint")
	weld.Part0 = weapon
	weld.Part1 = arm
	weld.Parent = weapon
	weapon.Parent = arm.Parent
	return weapon
end

module.SwordAttack = function(player, BossHumanoidRootPart, BossHumanoid)
	local myRoot = player:FindFirstChild("HumanoidRootPart")
	local unseathSound = Sounds.BMUnsheath
	local slashSound = Sounds.BMSwordSlash
	local lungeSound = Sounds.BMSwordLunge
	local rootPos
	local POSITION
	local sword = equipWeapon("Sword", BossHumanoidRootPart.Parent["Right Arm"])
	animations[4]:Play()
	unseathSound:Play()
	task.wait(0.4)
	
	for i = 1, 5 do --attacks 5 times
		rootPos = plrVector(myRoot, BossHumanoidRootPart)
		POSITION =  rootPos + (myRoot.CFrame.LookVector * 4.5)
		BossHumanoidRootPart.CFrame = CFrame.new(POSITION, rootPos)
		if i == 5 then
			sword.Orientation = Vector3.new(-90, 0, 0) --Here i try to rotate it but it doesnt work
			animations[3]:Play()
			lungeSound:Play()
		else
			animations[math.random(1, 2)]:Play()
			slashSound:Play()		
		end
		task.wait(0.7)
	end
	sword:Destroy()
end

// Try using a RigidConstraint :slight_smile: //


// What are RigidConstraints? :

RigidConstraints, as the name suggests, are constraints that rigidly connect objects. For example, if you wanted to keep a BasePart locked in place on top of another BasePart you would add Attachments to each BasePart and a RigidConstraint connecting those attachments.

Then voilà, the BaseParts should be seamlessly connected.

For you, you will need an attachment in the handle and an attachment in the hand.


// Rotation :

As for rotation, trial and error works well enough here, test out rotation using a default rig until you get the desired result. You should leave the RigidConstraint inside the sword with the default rotation you got from testing. From there, when you spawn the sword you can link the handle attachment to the hand attachment. Finally, you can programmatically rotate it how you like by rotating the attachments.

Working with rotation is primarily trial and error.


I hope this helps! :smile:

2 Likes

The other thing you could do it attach it to the hand Attachment, then make up an animation that includes the sword movement.

1 Like

It worked perfectly this way! thank you.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.