How to make AI push other characters like Gotta Sweep from Baldi's Basics?

Could someone help me with this? I don’t really know how to achieve this effect. But that doesn’t mean I didn’t try to do it!

1 Like

Just make the AI Character MoveTo() the player’s position and when that is done, add a vector force to move the character like done in this script below:

local AI = script.Parent
local AIHrp = AI:WaitForChild("HumanoidRootPart")
local plrs = game:GetService("Players")

local reachedPlr = false
local pushForce = 35000 -- how much push force, keep quite high

function applyPush(character, direction)
	local humanoidRP = character:FindFirstChild("HumanoidRootPart")
	
	if humanoidRP then
		local attachment = Instance.new("Attachment")
		attachment.Parent = humanoidRP

		local vectorForce = Instance.new("VectorForce")
		vectorForce.Force = direction * pushForce
		vectorForce.Attachment0 = attachment
		vectorForce.RelativeTo = Enum.ActuatorRelativeTo.World -- moves relative to the world
		vectorForce.Parent = humanoidRP

		game:GetService("Debris"):AddItem(vectorForce, 0.25)
		game:GetService("Debris"):AddItem(attachment, 0.25)
	end
end

plrs.PlayerAdded:Connect(function(plr)
	local char = plr.Character or plr.CharacterAdded:Wait()
	local hrp = char:FindFirstChild("HumanoidRootPart")
	
	local moveTo = AI:FindFirstChildOfClass("Humanoid"):MoveTo(hrp.Position, hrp)
	
	AI:FindFirstChildOfClass("Humanoid").MoveToFinished:Connect(function(reached)
		if reached and not reachedPlr then
			reachedPlr = true
			
			local PushDirection = (hrp.Position - AIHrp.Position).Unit
			applyPush(char, PushDirection)
			
			print("Reached")
			AI:FindFirstChildOfClass("Humanoid"):MoveTo(AIHrp.Position, AIHrp)
		end
	end)
end)

If you want to use this go ahead, I quickly made it, add a server script into your AI and you’re done. However this would need heavy modifying to be up to your liking, this only checks when a plr joins and chases them and when reached, add knockback. This is very basic so I advise you look at some tutorials for AI pathfinding.

Let me know if you have any other issues.

3 Likes

I already made my AI pathfinding but thanks :slight_smile:

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