How to push NPCs away from the player? I made a murder script from the back of an NPC. I want the NPC to push away from the player a little at the end. How can i do this?
local TCharacter = Target.Character
local THumanoid = TCharacter and TCharacter:FindFirstChild("Humanoid")
local TRootPart = TCharacter and TCharacter:FindFirstChild("HumanoidRootPart")
local FightTrigger = TRootPart
BHumanoid.Touched:Connect(function(hit)
if hit.Name == "FinisherHitBox" then
local lookat = CFrame.lookAt(BRootPart.Position, TRootPart.Position)
BRootPart.CFrame = lookat
local kilng2track = THumanoid:LoadAnimation(killed)
kilng2track:Play()
kild1track:Play()
TRootPart.CFrame = BRootPart.CFrame * CFrame.new(0,0,-1.2)
BRootPart.Anchored = true
TRootPart.Anchored = true
kild1track.Stopped:Wait()
BRootPart.Anchored = false
TRootPart.Anchored = false
end
end)
apply a body mover to the root part of the npc, like linearvelocity or bodyvelocity
If it’s not difficult, can you give me an example of how to do this?
local bv = Instance.new("BodyVelocity")
bv.MaxForce = Vector3.new(math.huge, 0, math.huge)
bv.Velocity = Direction * 10 -- replace direction with something like the players HumanoidRootPart.CFrame.LookVector and the 10 with the amount of force (just a number)
bv.Parent = NpcHumanoidRootPart -- replace with the root part of the npc
game.Debris:AddItem(bv, .2) -- replace .2 with the duration
local att = Instance.new("Attachment", hrp) -- replace hrp with NPC HumanoidRootPart
att.Axis = Vector3.new(0,0,-90)
local vel = Instance.new("LinearVelocity")
vel.VelocityConstraintMode = Enum.VelocityConstraintMode.Line
vel.LineDirection = hrp.CFrame.LookVector -- replace with players HumanoidRootPart.CFrame.LookVector
vel.LineVelocity = 100 -- replace 100 with amount of force
vel.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
vel.Attachment0 = att
vel.MaxForce = math.huge
vel.Parent = hrp
game.Debris:AddItem(att, .2) -- replace .2 with duration
game.Debris:AddItem(vel, .2) -- keep the same duration as the previous
1 Like