Npc Movement, need help!

  1. What do you want to achieve?
    hello, I’m trying to make a movement system using a tweened CFrame, for an NPC (a boss that’ll chase a player)

  2. What is the issue?
    when the player is standing still the boss would teleport underneath the player or out the map somewhere or even when the player is above something the Npc would act up by teleporting underneath the map and or above the player

  3. What solutions have you tried so far?
    I’ve got some help from looking at some dev forums posts but other than that i did it solo.

	local StartAnimationForJeff3 = character.Humanoid:LoadAnimation(
		script.Parent.Parent.AnimationList.StartAnimations.AnimationThree)
	local NumberOfAttacks = 0
	StartAnimationForJeff3:Play()
	StartAnimationForJeff3:Stop()
	local function Attackone()
		if #PlayersInBossFight ~= 0 then
			Attackmodule.RandomPlayer()
			repeat 
				task.wait(1)
				local info = TweenInfo.new(0.7, Enum.EasingStyle.Linear, Enum.EasingDirection.In,0,false,0)
				local goals = {Position = Vector3.new(RandomPlayer.Character.PrimaryPart.Position.X, character.Parent.Middle.Position.Y, RandomPlayer.Character.PrimaryPart.Position.Z);}
				local movingtolocation = TweenService:Create(character.PrimaryPart, info, goals)
				movingtolocation:Play()
				local info = TweenInfo.new(0.3, Enum.EasingStyle.Linear, Enum.EasingDirection.In,0,false,0)
				local goals = {CFrame = CFrame.lookAt(character.PrimaryPart.Position, Vector3.new(RandomPlayer.Character.PrimaryPart.Position.X, character.Parent.Middle.Position.Y, RandomPlayer.Character.PrimaryPart.Position.Z));}
				local lookat = TweenService:Create(character.PrimaryPart, info, goals)
				lookat:Play()
				movingtolocation.Completed:Connect(function()
					StartAnimationForJeff3:Play()
					task.wait(2)
					NumberOfAttacks = NumberOfAttacks + 1
				end)
			until  NumberOfAttacks ~= 6
			StartAnimationForJeff3:Play()
			StartAnimationForJeff3:Stop()
		end
	end
	local AttackoneFunction = coroutine.wrap(Attackone)
	AttackoneFunction()
1 Like

Do not put “Y” position, this can cause various problems in the vertical system. Well I removed them so try using this code of mine:

As a reminder that if the “Enemy” wants to follow the player up a ladder then this will not give him any problem.

local StartAnimationForJeff3 = character.Humanoid:LoadAnimation(
    script.Parent.Parent.AnimationList.StartAnimations.AnimationThree)
local NumberOfAttacks = 0
StartAnimationForJeff3:Play()
StartAnimationForJeff3:Stop()
local function Attackone()
    if #PlayersInBossFight ~= 0 then
        Attackmodule.RandomPlayer()
        repeat 
            task.wait(1)
            local info = TweenInfo.new(0.7, Enum.EasingStyle.Linear, Enum.EasingDirection.In,0,false,0)
            local goals = {Position = Vector3.new(RandomPlayer.Character.PrimaryPart.Position.X, 0, RandomPlayer.Character.PrimaryPart.Position.Z);}
            local movingtolocation = TweenService:Create(character.PrimaryPart, info, goals)
            movingtolocation:Play()
            local info = TweenInfo.new(0.3, Enum.EasingStyle.Linear, Enum.EasingDirection.In,0,false,0)
            local goals = {CFrame = CFrame.lookAt(character.PrimaryPart.Position, Vector3.new(RandomPlayer.Character.PrimaryPart.Position.X, 0, RandomPlayer.Character.PrimaryPart.Position.Z));}
            local lookat = TweenService:Create(character.PrimaryPart, info, goals)
            lookat:Play()
            movingtolocation.Completed:Connect(function()
                StartAnimationForJeff3:Play()
                task.wait(2)
                NumberOfAttacks = NumberOfAttacks + 1
            end)
        until  NumberOfAttacks ~= 6
        StartAnimationForJeff3:Play()
        StartAnimationForJeff3:Stop()
    end
end
local AttackoneFunction = coroutine.wrap(Attackone)
AttackoneFunction()
1 Like

it would still clip into the floor

Do you want the NPC to walk to the player? If yes why do you want to achieve this with tweening? You can just use NPC:MoveTo()

Now, if you want to make a NPC that will chase the player, you will need to use and pathfinding.

In addition can see and this post:

1 Like