local debounce = false
local function returnMass(model)
local TotalMass = 0
for _, descendant in (model:GetDescendants()) do
if descendant:IsA("BasePart") then
TotalMass += descendant:GetMass()
end
end
return TotalMass
end
script.Parent.Touched:Connect(function(hit)
if hit and hit.Parent and not debounce then
local tagHum = hit.Parent:FindFirstChild("Humanoid")
local root = hit.Parent:FindFirstChild("HumanoidRootPart")
if tagHum and root then
debounce = true
local mass = returnMass(root.Parent)
root.AssemblyLinearVelocity = Vector3.new(0, 100, 0) * mass
task.wait(2)
debounce = false
end
end
end)
When you touch this part, the character is supposed to be launched upwards. A basic NPC goes flying, but my own character stays on the ground and seems unaffected. When I jump, it only slightly bounces me up a 1.5 studs or so.
Increase the force. It really is that simple. Humanoids are adverse to moving due to the player controller, so you gotta kinda fling 'em. I also suggest just using BasePart:ApplyImpulse(Vector3)
Also, you can get the AssemblyMass (the mass of all connected parts) from a player by getting its AssemblyMass property rather than the function you used. It’s more accurate.
Even using :ApplyImpulse(), .AssembyMass and a bigger force, nothing changes. This time my character doesn’t budge at all, whilst the NPC is being rocketed.
Did you do any print()'s to check if it was even actually pushing the player, like running a print when a player touches it so you know the code is even executing
it dawned on me that you were doing this through the server (Idk why i didn’t immediately realize), which means network ownership is an issue because AssemblyLinearVelocity is not replicated.
Heres an example using a VectorForce, which will create replicated physics (and thus work, i tested it myself)
script.Parent.Touched:Connect(function(hit)
print("hit")
if hit and hit.Parent and not debounce then
local tagHum = hit.Parent:FindFirstChild("Humanoid")
local root: Part = hit.Parent:FindFirstChild("HumanoidRootPart")
if tagHum and root then
debounce = true
print("firing")
local mass = root.AssemblyMass
local force = Vector3.new(0,1000,0)*mass
local vf2 = Instance.new("VectorForce")
vf2.ApplyAtCenterOfMass = true
vf2.Attachment0 = root.RootAttachment
vf2.Force = force
vf2.Parent = root
task.wait(0.1)
vf2:Destroy()
task.wait(2)
debounce = false
end
end
end)
also to do mass properly, you actually wanna multiply it by workspace.Gravity, to counteract gravity. but I didn’t wanna change anything physics wise without you noticing
root.Velocity = script.Parent.CFrame.lookVector * 100 -- Push the Player back
Back then a simple line of that used to do the trick.
When applying force from the side, it appears that you’re significantly less impacted by the force when grounded compared to in the air (when jumping). Do you have to run a seperate check to see whether the player is airborne or not, and then adjust the force accordingly?
It’s because of friction, you could run a check like that by checking the FloorMaterial property of the Humanoid. If it’s Air, then it means they’re… in the air.
You can also set a specific velocity rather than a force (its like setting speed versus amount of push) by using a LinearVelocity rather than a VectorForce, which will be much more aggressive and accurate to a set speed. But idk if its like necessary