#Semi-advanced NPC randomly getting stuck while hunting the player down

13 messages · Page 1 of 1 (latest)

wanton valve
#

Why are you needing to get the tubby's position via the server?

tall pewter
wanton valve
#

Would it be easier to not change his position? Can you try just changing the orientation instead and use the look CFrames rotation?

I just wonder how sending the position information like that is affecting it

Did this happen before the rotation was added?

tall pewter
#

I'm still debating whether it's the .LookAt() cancelling the :MoveTo() somehow even with a replicated variant of the tubby's position

wanton valve
#

Well .LookAt() returns a new CFrame at that position and looking at that target, so you're setting the position to whatever the server said it was at when the function returns, which might not be where it intends to go, causing the jittering as those two positions fight.

Now I'm not 100% sure if that's causing it to not go near the player.

tall pewter
# wanton valve Well `.LookAt()` returns a new CFrame at that position and looking at that targe...

That very much could be the reasoning; which would imply I'd have to time the :MoveTo() and the :LookAt() perfectly to balance them both out; which could cause a bit of choppiness as he tries to maintain his look on the player while balancing out the wait time between each pathfinding attempt

I'm wondering if there's any other alternative to :LookAt() - or any other variant of balancing them both out

wanton valve
#

Maybe you should try just changing the orientation of the root part to tubby pos - player pos, multiplying the result by Vector3.yAxis so it doesn't make it tilt or roll, just spin

tall pewter
#

That could definitely work no doubt; i'll give it a shot and let you know how it goes

Thanks for the help 👍

tall pewter
#

I've implemented a couple things till I got the result I desired; and once more he's returned to the jittering after a random period of time; sadly :(

#

Here's the updated code; if needed

#

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local hrp = character:WaitForChild("HumanoidRootPart")

game:GetService("RunService").RenderStepped:Connect(function()
    if workspace:FindFirstChild("slendytubby") ~= nil and workspace.slendytubby:FindFirstChild("SlendytubbyMesh") ~= nil then
        local tubbyPosition = game.ReplicatedStorage.remoteFunctions.tubbyPosition:InvokeServer()
        local tubbyMesh = workspace.slendytubby.SlendytubbyMesh

        local direction = (hrp.Position - tubbyPosition).Unit
        local newOrientation = CFrame.new(tubbyPosition, tubbyPosition + direction)

        tubbyMesh.CFrame = newOrientation
    end
end)
wanton valve