Description of the problem
I was making a tool for a small game I’m working on, and it’s basically a toilet plunger that you can throw that uses a rope constraint. It works exactly how I want it to, until the player actually throws the plunger. When the player throws the plunger and jumps, the player gets flung for some reason.
Here’s a video that shows you what I’m talking about:
Code
There are two rope constraints. One is from the rope mesh that goes to the handle of the tool, and the other is from the handle of the tool to the plunger’s handle. When the player throws the plunger, the rope constraint that goes from the tool’s handle to the plunger’s handle gets disabled and is invisible. Then, the rope constraint that goes from the rope mesh to the handle is changed to go to from the rope mesh to the handle of the plunger. The length of this rope is also changed to 30 from its default length of 5.
-- called when the tool is being charged
function chargePlunger()
local swingAnimation = animations["Swing"]
swingAnimation:Play(SWING_CHARGE_TIME, 1, 0)
chargeStartTick = tick()
swung = false
end
-- called when the plunger is thrown
function throwPlunger()
ropeConstraint2.Visible = false
ropeConstraint2.Enabled = false
ropeConstraint.Attachment1 = plungerHandleAttachment
ropeConstraint.Length = THROW_ROPE_DISTANCE
end
-- called when the plunger is attempted to be swung
function attemptToSwingPlunger()
if swinging then
return
end
if swung then
return
end
local swingAnimation = animations["Swing"]
if tick() - chargeStartTick >= SWING_CHARGE_TIME then
print("Swinging")
swinging = true
swingAnimation:AdjustSpeed(1)
local connection = swingAnimation:GetMarkerReachedSignal("ThrowPlunger"):Connect(function()
throwPlunger()
end)
swingAnimation.Stopped:Wait()
connection:Disconnect()
swinging = false
swung = true
else
print("Animation Stopped")
swingAnimation:Stop()
end
end
Conclusion & Extra Details
Is there any way to fix this behavior? I just don’t want the player to be flung whenever the player jumps after the plunger is thrown. I can’t seem to figure out why this even happens. The plunger is not massless, but that shouldn’t affect the character in any way. Has anyone had this problem before?