Apply Impulse not working

Hello developers! I am currently working on a game and I am using “ApplyImpulse” to send the player flying out of the cannon but for some reason it doesn’t fling me. When you reset it no longer works and the player flops to the floor. If someone can help me out I’d appreciate it a bunch! Thank you.

Issue I am having
https://gyazo.com/3e6ce9471eda1ab80e071d2f9bbb5b10

Server Script

-- Cannon Server_ Handler
-- d5_ax
-- December 3, 2022

--[[
	
	Server:
		
	


	Client:
		
	

--]]



local CannonServer_Handler = {Client = {}}




function CannonServer_Handler:Start()
	
	local ReplicatedStorage = game:GetService("ReplicatedStorage")
	local Remotes = ReplicatedStorage:WaitForChild("RemoteEvents")
	local ProxyRemote = Remotes:WaitForChild("ProxyRemote")
	local ProximityPromptService = game:GetService("ProximityPromptService")

	local Cannons = game.Workspace:WaitForChild("Cannons")
	
	--// Add ProximityPrompts to cannons
	for i,v in pairs(Cannons:GetChildren()) do
		if v.Name == "Cannon" then
			local ProximityPrompt = v:WaitForChild("ProximityPrompt")
			ProximityPrompt.HoldDuration = 0.5
		end
	end
	
	--// Send prompt signal to client
	local function onPromptTriggered(promptObject, player)
		ProxyRemote:FireClient(player)
	end
	
	ProximityPromptService.PromptTriggered:Connect(onPromptTriggered)
	
end


function CannonServer_Handler:Init()
	

end


return CannonServer_Handler

Client Script

-- Cannon Client_ Handler
-- d5_ax
-- December 3, 2022

--[[
	

--]]



local CannonClient_Handler = {}


function CannonClient_Handler:Start()
	
	local ts = game:GetService("TweenService")
	local ReplicatedStorage = game:GetService("ReplicatedStorage")
	
	local Remotes = ReplicatedStorage:WaitForChild("RemoteEvents")
	local ProxyRemote = Remotes:WaitForChild("ProxyRemote")

	local x = game.Players.LocalPlayer
	local character = x.Character or x.CharacterAdded:Wait()
	local HRP = character:WaitForChild("HumanoidRootPart")
	local Humanoid = character:WaitForChild("Humanoid")
	local UpperTorso = character:WaitForChild("UpperTorso")

	local stateType = Enum.HumanoidStateType
	
	--// Set player inside cannon
	--[[local function GetInCannon()
		HRP.Anchored = true
		character:MoveTo(Vector3.new(MainBody.Position.X, MainBody.Position.Y, MainBody.Position.Z))
		HRP.CFrame = MainBody.CFrame * CFrame.Angles(0,math.rad(0, 10, 0),0) + Vector3.new(0,0,0)
	end]]--
	
	--// Cannon fire function
	local function FireCannon()

		wait(0.5)

		HRP.Anchored = false

		HRP:ApplyImpulse(Vector3.new(0,500,100)) -- Apply the Character Impulse
		
		--// Stuff for Ragdoll don't mind this
		x.Character.Humanoid:SetStateEnabled(stateType.GettingUp, false)
		x.Character.Humanoid:ChangeState(stateType.FallingDown)
		local UTJoint = x.Character:FindFirstChild("UpperTorso")
		local LTJoint = x.Character:FindFirstChild("LowerTorso")
		local RUA = x.Character:FindFirstChild("RightUpperArm")
		local LUA = x.Character:FindFirstChild("LeftUpperArm")
		local RUL = x.Character:FindFirstChild("RightUpperLeg")
		local LUL = x.Character:FindFirstChild("LeftUpperLeg")
		local RLA = x.Character:FindFirstChild("RightLowerArm")
		local LLA = x.Character:FindFirstChild("LeftLowerArm")
		local RLL = x.Character:FindFirstChild("RightLowerLeg")
		local LLL = x.Character:FindFirstChild("LeftLowerLeg")
		local RH = x.Character:FindFirstChild("RightHand")
		local LH = x.Character:FindFirstChild("LeftHand")
		local RF = x.Character:FindFirstChild("RightFoot")
		local LF = x.Character:FindFirstChild("LeftFoot")
		local HRP = x.Character:FindFirstChild("HumanoidRootPart")
		local Torso x.Character.UpperTorso.Waist.Part0 = UTJoint
		local Torso2 x.Character.UpperTorso.Waist.Part1 = UTJoint
		local RUAJoint x.Character.RightUpperArm.RightShoulder.Part0 = RUA
		local RUAJoint2 x.Character.RightUpperArm.RightShoulder.Part1 = RUA
		local LUAJoint x.Character.LeftUpperArm.LeftShoulder.Part0 = LUA
		local LUAJoint2 x.Character.LeftUpperArm.LeftShoulder.Part1 = LUA
		local RULJoint x.Character.RightUpperLeg.RightHip.Part0 = RUL
		local RULJoint2 x.Character.RightUpperLeg.RightHip.Part1 = RUL
		local LULJoint x.Character.LeftUpperLeg.LeftHip.Part0 = LUL
		local LULJoint2 x.Character.LeftUpperLeg.LeftHip.Part1 = LUL
		local RLAJoint x.Character.RightLowerArm.RightElbow.Part0 = RLA
		local RLAJoint2 x.Character.RightLowerArm.RightElbow.Part1 = RLA
		local LLAJoint x.Character.LeftLowerArm.LeftElbow.Part0 = LLA
		local LLAJoint2 x.Character.LeftLowerArm.LeftElbow.Part1 = LLA
		local RLLJoint x.Character.RightLowerLeg.RightKnee.Part0 = RLL
		local RLLJoint2 x.Character.RightLowerLeg.RightKnee.Part1 = RLL
		local LLLJoint x.Character.LeftLowerLeg.LeftKnee.Part0 = LLL
		local LLLJoint2 x.Character.LeftLowerLeg.LeftKnee.Part1 = LLL
		local RHJoint x.Character.RightHand.RightWrist.Part0 = RH
		local RHJoint2 x.Character.RightHand.RightWrist.Part1 = RH
		local LHJoint x.Character.LeftHand.LeftWrist.Part0 = LH
		local LHJoint2 x.Character.LeftHand.LeftWrist.Part1 = LH
		local RJoint x.Character.RightFoot.RightAnkle.Part0 = RF
		local RFJoint2 x.Character.RightFoot.RightAnkle.Part1 = RF
		local LFJoint x.Character.LeftFoot.LeftAnkle.Part0 = LF
		local LFJoint2 x.Character.LeftFoot.LeftAnkle.Part1 = LF
		--Collision
		character.UpperTorso.CollisionGroupId = 0
		character.LeftLowerArm.CollisionGroupId = 0
		character.RightLowerArm.CollisionGroupId = 0
		character.LeftLowerLeg.CollisionGroupId = 0
		character.RightLowerLeg.CollisionGroupId = 0
	end
	
	--// Fire the cannon
	ProxyRemote.OnClientEvent:Connect(function(player)
		FireCannon()
	end)
	
end


function CannonClient_Handler:Init()
	
end


return CannonClient_Handler

Try setting LinearVelocity, that might help

1 Like

Using a Linear Velocity seems to just drag me on the ground not really shoot me in the air ;(

I believe with :ApplyImpulse() you’re supposed to multiply the velocity by the parts mass.

I believe the impulse should be applied after the state is changed to avoid humanoid interference.

		x.Character.Humanoid:SetStateEnabled(stateType.GettingUp, false)
		x.Character.Humanoid:ChangeState(stateType.FallingDown)

		HRP:ApplyImpulse(Vector3.new(0,500,100)) -- Apply the Character Impulse
1 Like

If you do use .AssemblyLinearVelocity you should add the fling velocity to your current velocity instead of setting the velocity.

1 Like

So Applying it before hand is causing the ragdoll to pull itself in a downward position? I tested the Impulse before hand with a part without the ragdoll and worked fine

This doesn’t seem to change anything either sadly. It does push it slightly more than before but the same problem occurs of the player not launching the second time :thinking:

The conditions for a part are different for a ragdoll so just because it works for a part doesn’t mean it will work for a ragdoll. These factors could have influenced change and caused the error.

  • Increased mass

  • Some sort of ragdoll constraints odd behavior, especially when you enable and reenable them. There will be a reaction force that will cancel out the impulse.

Perhaps add a wait to stabilize the ragdoll then apply impulse with an increased amount of force.

local function ragdoll(x, character, stateType)
	--// Stuff for Ragdoll don't mind this
	x.Character.Humanoid:SetStateEnabled(stateType.GettingUp, false)
	x.Character.Humanoid:ChangeState(stateType.FallingDown)
	local UTJoint = x.Character:FindFirstChild("UpperTorso")
	local LTJoint = x.Character:FindFirstChild("LowerTorso")
	local RUA = x.Character:FindFirstChild("RightUpperArm")
	local LUA = x.Character:FindFirstChild("LeftUpperArm")
	local RUL = x.Character:FindFirstChild("RightUpperLeg")
	local LUL = x.Character:FindFirstChild("LeftUpperLeg")
	local RLA = x.Character:FindFirstChild("RightLowerArm")
	local LLA = x.Character:FindFirstChild("LeftLowerArm")
	local RLL = x.Character:FindFirstChild("RightLowerLeg")
	local LLL = x.Character:FindFirstChild("LeftLowerLeg")
	local RH = x.Character:FindFirstChild("RightHand")
	local LH = x.Character:FindFirstChild("LeftHand")
	local RF = x.Character:FindFirstChild("RightFoot")
	local LF = x.Character:FindFirstChild("LeftFoot")
	local HRP = x.Character:FindFirstChild("HumanoidRootPart")
	local Torso x.Character.UpperTorso.Waist.Part0 = UTJoint
	local Torso2 x.Character.UpperTorso.Waist.Part1 = UTJoint
	local RUAJoint x.Character.RightUpperArm.RightShoulder.Part0 = RUA
	local RUAJoint2 x.Character.RightUpperArm.RightShoulder.Part1 = RUA
	local LUAJoint x.Character.LeftUpperArm.LeftShoulder.Part0 = LUA
	local LUAJoint2 x.Character.LeftUpperArm.LeftShoulder.Part1 = LUA
	local RULJoint x.Character.RightUpperLeg.RightHip.Part0 = RUL
	local RULJoint2 x.Character.RightUpperLeg.RightHip.Part1 = RUL
	local LULJoint x.Character.LeftUpperLeg.LeftHip.Part0 = LUL
	local LULJoint2 x.Character.LeftUpperLeg.LeftHip.Part1 = LUL
	local RLAJoint x.Character.RightLowerArm.RightElbow.Part0 = RLA
	local RLAJoint2 x.Character.RightLowerArm.RightElbow.Part1 = RLA
	local LLAJoint x.Character.LeftLowerArm.LeftElbow.Part0 = LLA
	local LLAJoint2 x.Character.LeftLowerArm.LeftElbow.Part1 = LLA
	local RLLJoint x.Character.RightLowerLeg.RightKnee.Part0 = RLL
	local RLLJoint2 x.Character.RightLowerLeg.RightKnee.Part1 = RLL
	local LLLJoint x.Character.LeftLowerLeg.LeftKnee.Part0 = LLL
	local LLLJoint2 x.Character.LeftLowerLeg.LeftKnee.Part1 = LLL
	local RHJoint x.Character.RightHand.RightWrist.Part0 = RH
	local RHJoint2 x.Character.RightHand.RightWrist.Part1 = RH
	local LHJoint x.Character.LeftHand.LeftWrist.Part0 = LH
	local LHJoint2 x.Character.LeftHand.LeftWrist.Part1 = LH
	local RJoint x.Character.RightFoot.RightAnkle.Part0 = RF
	local RFJoint2 x.Character.RightFoot.RightAnkle.Part1 = RF
	local LFJoint x.Character.LeftFoot.LeftAnkle.Part0 = LF
	local LFJoint2 x.Character.LeftFoot.LeftAnkle.Part1 = LF
	--Collision
	character.UpperTorso.CollisionGroupId = 0
	character.LeftLowerArm.CollisionGroupId = 0
	character.RightLowerArm.CollisionGroupId = 0
	character.LeftLowerLeg.CollisionGroupId = 0
	character.RightLowerLeg.CollisionGroupId = 0

end

local function FireCannon()

	wait(0.5)

	HRP.AssemblyAngularVelocity = Vector3.zero
	HRP.AssemblyLinearVelocity = Vector3.zero -- reset velocity to zero, initial conditions
	HRP.Anchored = false

	ragdoll(x, character, stateType) --ragdoll
	task.wait(0.5) --wait for forces to stabilize further
	--Apply factor of 1000 to increase forces for testing purposes
	HRP:ApplyImpulse(Vector3.new(0,500,100)*1000) -- Apply the Character Impulse

end
2 Likes

PlatformStand the humanoid and make the impulse forces (DirectionVector * (AssemblyMass * Gravity * PowerValue) ) then apply animations? Making sure to watch root priority too.

I have something similar and this is just what I recall offhand from it. However it doesn’t use ragdoll. Just constraints.

1 Like

Makes a bit more sense now, although this did work better still have something causing the AppyImpulse to not work a second time after the player has died. I have tried adding a check for if the player exist and or has respawned.

it is because the character is destroyed and so a new hrp is created and the function only propells the old destroyed hrp.

you will need to use .CharacterAdded or put the script inside StarterCharacterScripts to reset the script on character respawn.

1 Like

I appreciate you’re help, I added a extra check for the player on the client and it seems to work now. Thank you very much for your time! :call_me_hand:

1 Like

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