#Semi-advanced NPC randomly getting stuck while hunting the player down
13 messages · Page 1 of 1 (latest)
Changing it directly would cancel his :MoveTo()
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?
I'm not very used to CFrames, and found .LookAt() offered me the same creepy feeling the original Slendytubby game gave towards the player
This doesn't occur without the clientside script modifying the tubby's CFrame; however I do still find it necessary to give off the result I want
I'm still debating whether it's the .LookAt() cancelling the :MoveTo() somehow even with a replicated variant of the tubby's position
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.
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
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
That could definitely work no doubt; i'll give it a shot and let you know how it goes
Thanks for the help 👍
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)
you're still setting the tubby's CFrame, which includes position
I mentioned changing just Orientation on the PrimaryPart to avoid setting the CFrame which sets position