How to use ApplyImpulse?

I’m trying to make a throwable ball but it doesn’t really getting shot out. I want it to shoot out to the direction my HumanoidRootPart is facing. I’m trying to implement this using ApplyImpulse but I don’t really know how to use such thing. I’ve been to the wiki but I didn’t understand anything.

This is what I have so far:

Client:

local tool = script.Parent
local remoteEvent = tool.RemoteEvent

tool.Activated:Connect(function()
	remoteEvent:FireServer()
end)

Server:

local tool = script.Parent
local handle = tool.Handle
local remoteEvent = tool.RemoteEvent

remoteEvent.OnServerEvent:Connect(function(player)
	local character = player.Character or player.CharacterAdded:Wait()
	local rootPart = character:FindFirstChild("RootPart")
	
	local projectile = handle:Clone()	
	
	projectile:ApplyImpulse(Vector3.new(10000,0,0))
	projectile.Parent = workspace
end)
4 Likes

Last time I checked, it doesn’t work, so just change BasePart.Velocity on the root part BasePart:GetRootPart()

Actually you’ll want BasePart.AssemblyLinearVelocity, since BasePart.Velocity is deprecated and apparently can work a little better than the latter.

3 Likes

I literally said that it doesn’t work. I’ve tried Assembly stuff myself and they didn’t work the last time I checked

1 Like

Works on my machine:

I changed the code up a bit though, you likely have to parent it first though

local tool = script.Parent
local handle = tool:WaitForChild("Handle")
local remoteEvent = tool:WaitForChild("RemoteEvent")

remoteEvent.OnServerEvent:Connect(function(player)
	local character = player.Character or player.CharacterAdded:Wait()
	local rootPart = character:FindFirstChild("RootPart")

	local projectile = handle:Clone()	
	
	projectile.Parent = workspace
	projectile:ApplyImpulse(Vector3.new(0, 0, 10))
end)

and I used a lower impulse for testing purposes. OP had it at 10k on the X axis, where I have it to 10 on the Z.

2 Likes

Huh. Either they fixed it or BodyForce or NetworkOwnership played a role

1 Like

They just weren’t live, there was no bug. Although the functions have been live for a while now. And I never used a body force or used network ownership?

Uhhh, do you know how to apply the force to the direction the rootPart is looking?

Yes, you can use rootPart.CFrame.LookVector as the impulse then multiply it by some scalar for more force

2 Likes

Did I miss anything?

local tool = script.Parent
local handle = tool.Handle
local remoteEvent = tool.RemoteEvent

remoteEvent.OnServerEvent:Connect(function(player)
	local character = player.Character or player.CharacterAdded:Wait()
	local rootPart = character:FindFirstChild("RootPart")
	
	local projectile = handle:Clone()
	
	projectile.Parent = workspace
	
	projectile:ApplyImpulse(rootPart.CFrame.LookVector * 1000)
end)

You didn’t define it, instead write character.PrimaryPart.CFrame.LookVector * 1000

7 Likes

So would this work in a case of propelling the player forwards?

3 Likes

how could you make it so the character is pushed a little upwards too?

i know this is pretty old and im necroposting but just incase he never found out and/ or for future reference im just gonna say, you’d have to create a new vector saying local vector = Vector3.new(character.PrimaryPart.CFrame.LookVector.X, --insert y here, character.PrimaryPart.CFrame.LookVector.Z and after that write projectile:ApplyImpulse(vector * 1000)

1 Like