Bodyposition freezing midair?

Alright, so, if you look closely, the npc freezes in midair for a bit before falling. Here’s my script, help me fix it, please! :slight_smile:

local attFrame = CFrame.new(AttackCFrame.Position,hum.Parent.PrimaryPart.CFrame.Position) 
		local cframe = CFrame.new(attFrame.Position + Vector3.new(0,intensity[1],0)) + attFrame.LookVector * intensity[2] --hum.Parent.PrimaryPart.CFrame
		local bodypos = Instance.new("BodyPosition",hum.Parent.PrimaryPart)
		local human = hum.Parent:FindFirstChildOfClass("Humanoid")
		bodypos.Position= cframe.Position
		bodypos.MaxForce = Vector3.new(99999,99999,99999)
		bodypos.P = 9999
		bodypos.ReachedTarget:Connect(function()
			bodypos:Destroy()
		end)

I don’t think they “freeze” midair, all that’s happening is the BodyPosition is reaching the goal, but it’s not getting deleted the moment it’s reaching the goal, so it suspends there until it’s deleted.

So what you wanna do instead is use ApplyImpulse with a vector pointing to the goal.

1 Like

ohhh. tysm!
I’ll give this a shot! :slight_smile:

hmmm. Didn’t work. How do I use applyimpulse?

ApplyImpulse takes in a Vector3 and adds it as force to the targeted part.

From my reading ApplyImpulse will only work if the side its fired from has network ownership over the target. So if a server tries to apply a velocity to the player, it wont work unless the server has network ownership over character’s primary part.

SetNetworkOwner(nil)

This sets the network ownership of a part to the server, to set it to a player you would replace nil with a Player object. Heres a hyperlink to learn more about Network Ownership

An alternative to this would be to use remote events to apply knockback to the target on their client.

1 Like
function damagemod.Knockback(hum,AttackCFrame,intensity)
	if not hum.Parent.HumanoidRootPart:FindFirstChildOfClass("BodyPosition") then
		print("ee")
		local attFrame = CFrame.new(AttackCFrame.Position,hum.Parent.PrimaryPart.CFrame.Position) 
		local cframe = CFrame.new(attFrame.Position + Vector3.new(0,intensity[1],0)) + attFrame.LookVector * intensity[2] --hum.Parent.PrimaryPart.CFrame
		local bodypos = Instance.new("BodyVelocity",hum.Parent.PrimaryPart)
		local human = hum.Parent:FindFirstChildOfClass("Humanoid")
		bodypos.Velocity = cframe.Position
		bodypos.MaxForce = Vector3.new(99999,99999,99999)
		bodypos.P = 9999
		bodypos.ReachedTarget:Connect(function()
			bodypos:Destroy()
		end)
	end
end

Why not just listen for the “ReachedTarget” event to fire on the BodyPosition instance before destroying it? Instead of creating an additional thread of execution (with the spawn() global) and waiting for an arbitrary length of time (0.1 seconds). The ReachedTarget event of a BodyPosition instance will fire whenever the BodyPosition reaches its specified destination described by the “Position” property of the instance itself.

2 Likes

Ohhhh Thank you! I think this’ll work. Lemme give it a try! <3

Wait. It doesn’t work. It just flies into the sky and doesnt fall

That means that for whatever reason the BodyPosition instance isn’t reaching its designated target.

hmm. ty. ill look into it some more!

Wait. that’s not accurate.


It did reach the position.

I used printed out the bodyposition destination and it has reached it.

Also, it still freezes.

If “ReachedTarget” isn’t firing then the BodyPosition instance isn’t reaching its target. Unless you’re trying to claim that information for the official documentation is inaccurate.

This is the property I’m referring to which represents the goal of the BodyPosition.

I’m not trying to claim anything. I’m stating that there are no errors, and the event isn’t firing. It’s just a fact.

Taking another glance at your script I’ve noticed you aren’t setting the “.Position” property of the BodyPosition, this property describes the end-goal of the BodyPosition instance.

local BP = Instance.new("BodyPosition")
BP.Position = Vector3.new(0, 0, 0) --example

This is what I currently have:

local attFrame = CFrame.new(AttackCFrame.Position,hum.Parent.PrimaryPart.CFrame.Position) 
		local cframe = CFrame.new(attFrame.Position + Vector3.new(0,intensity[1],0)) + attFrame.LookVector * intensity[2] --hum.Parent.PrimaryPart.CFrame
		local bodypos = Instance.new("BodyPosition",hum.Parent.PrimaryPart)
		local human = hum.Parent:FindFirstChildOfClass("Humanoid")
		bodypos.Position= cframe.Position
		bodypos.MaxForce = Vector3.new(99999,99999,99999)
		bodypos.P = 9999
		bodypos.ReachedTarget:Connect(function()
			bodypos:Destroy()
		end)

got any idas? ;-; Im really lost here