Help with a retractable sword

  1. What do you want to achieve?
    I am currently trying to make a retractable sword, similar to how work a light saber from star wars

  2. What is the issue?
    So basically it is a tool since it is a weapon for players. But the main problem is that the blade doesnt keep the right position, it is always displaced from the origin or where it should be which is above the handle.

  3. What solutions have you tried so far?
    I tried looking on google. I found one solution which is Part:Resize(Enum.NormalId.Right, 1) but it still resize on both side.

Also here is more details:
i tried using Resize function which failed. Also i used CFrame + size which made my char moving. Finally i tried modifying the position of the blade with the size of the blade but at the end, the blade is displaced from the origin. Anyone know how to do it?

I would thank the one to find a solution

3 Likes

I think that that is a bug (Resize method not working properly), cause I encountered that problem myself as well. Displacing the sword yourself should work though.

Some pseudocode:

sword.CFrame = sword.CFrame + sword.CFrame.LookVector * lengthIncrement / 2
sword.Size = sword.Size + Vector3.new(0, 0, lengthIncrement)

the main problem with .CFrame is probably due to the Weld Constraint which make the player moving while the blade is growing

Oh I did not read that last part. It should still work in theory, since WeldConstraint only needs Part0 and Part1. Perhaps the sword part is just colliding with the handle? Can you try to turn the blade’s CanCollide off?

so i didn’t place the blade well ofc but most likely, this is what it does:
https://gyazo.com/f6b99411a35a511e57c1a30bb2bf3053

here is my code:

for i = 1, 10 do
	Blade.CFrame = Blade.CFrame * CFrame.new(-0.2, 0, 0)
	Blade.Size = Blade.Size + Vector3.new(0.4, 0, 0)
	wait()
end

The WeldConstraint should not be a problem “If a welded part’s Position is updated, the part will move but none of the connected parts will move with it. The weld will recalculate the offset from the other part based on the part’s new position.” - Developer Hub.

Yeah it shouldn’t but as my gif show, my char is moving even if i don’t move

I think that the blade is colliding with your character, since the CFrame is incorrect. Try using directional unitvectors:

sword.CFrame.LookVector * lengthIncrement / 2

This way, you can maintain the blades rotation. Also you might want to turn off CanCollide for the blade.

so, i tried your idea with unitdirectionnal thing and it fail, the blade is thousand stud away. Here is my code:

Value2.blade.Position = Value2.blade.CFrame.lookVector * 0.2
Value2.blade.Size = Value2.blade.Size + Vector3.new(0.4, 0, 0)

i also tried using Handle’s lookVector:

Value2.CFrame.lookVector * 0.2

If anyone got an answer, i would be thankfully

In case of someone will need it later

It’s been a while since now and i found a solution. The solution is pretty simple when we know how to do use it:
i just need to use a Weld (not WeldConstraint) and weld the blade and the handle. Then, i use handle.Cframe:ToObjectSpace(CFRAME) and that’s all

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