I’m trying to make an NPC with a pathfinding system that works with arms aiming at a player, but I keep going in circles because pathfinding breaks the aiming, when it has to take a path that faces away from the player, by the way the NPC I’m making is holding a gun and that’s another problem because I can’t seem to make the arms and the handle (gun) rigid so it rotates positioned the same way as adjusted.
The arms are supposed to be posed like this:
and i wanna make it so that it rotates positioned like that
For the aiming I’ve been doing:
local targetPosition = targetCharacter.HumanoidRootPart.Position
local torso = NPC.PrimaryPart or Torso
local lookPosition = Vector3.new(targetPosition.X, torso.Position.Y, targetPosition.Z)
local handleCFrame = Handle.CFrame
local directionWorld = (targetPosition - handleCFrame.Position).Unit
local directionLocal = Torso.CFrame:Inverse():VectorToObjectSpace(directionWorld)
local pitch = mathClamp(-math.asin(directionLocal.Y), 0, 0)
if Neck then Neck.C0 = originalNeckC0 * CFrame.Angles(pitch, 0, 0) end
if RightShoulder then RightShoulder.C0 = rightArmBaseC0 * CFrame.Angles(45, 0, -pitch) end
if LeftShoulder then LeftShoulder.C0 = CFrame.new(-0.5, 0.5, -1) * CFrame.Angles(0, math.rad(-45), math.rad(-90)) * CFrame.Angles(45, 0, pitch) end
if HandleJoint then HandleJoint.C0 = handleBaseC0 * CFrame.Angles(0, 0, -pitch) end
For pathfinding towards player:
local function chaseTarget(target)
local path = PathfindingService:CreatePath()
path:ComputeAsync((NPC.PrimaryPart or Torso).Position, target.Position)
if path.Status == Enum.PathStatus.Success then
for _, waypoint in ipairs(path:GetWaypoints()) do
if Humanoid.Health <= 0 then return end
if waypoint.Action == Enum.PathWaypointAction.Jump then
Humanoid.Jump = true
end
Humanoid:MoveTo(waypoint.Position)
Humanoid.MoveToFinished:Wait()
if workspace:FindPartOnRayWithIgnoreList(Ray.new((NPC.PrimaryPart or Torso).Position, (target.Position - (NPC.PrimaryPart or Torso).Position).Unit * 1000), {NPC}) then
while workspace:FindPartOnRayWithIgnoreList(Ray.new((NPC.PrimaryPart or Torso).Position, (target.Position - (NPC.PrimaryPart or Torso).Position).Unit * 1000), {NPC}) do
Humanoid:MoveTo(target.Position)
task.wait(0.2)
end
break
end
end
end
end
I’m all out of ideas, if anyone has had experience with this, please give ideas or advice on what to do.
