Moving enemy somewhere is buggy and not smooth i dont understand why

Hello.

About 2 days ago, I was working on making the enemy move, and I wanted to try it out myself.

Then when the enemy was moving, it started bugging out and not properly moving. I found out that it had to do with some type of script interfering with the movement (Which some type of script was).

I wanted to figure out why this script for positioning the characters is interfering with the movement script?

I have two types of scripts, and I dont know where the issue could possibly be for the enemy to be laggy and move.

These are what are messing up the enemy’s movement script.

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()

local humrp = char:WaitForChild('HumanoidRootPart')

game:GetService('RunService').RenderStepped:Connect(function()
	for _, MODEL in pairs(workspace:GetChildren()) do
		if MODEL:IsA('Model') and MODEL:FindFirstChild('DummyBot') then
			MODEL:WaitForChild('HumanoidRootPart').CFrame = CFrame.lookAt(MODEL:WaitForChild('HumanoidRootPart').Position, Vector3.new(humrp.CFrame.X, MODEL:WaitForChild('HumanoidRootPart').CFrame.Y, MODEL:WaitForChild('HumanoidRootPart').CFrame.Z))
			task.wait()
		end
	end
end)
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()

local humrp = char:WaitForChild('HumanoidRootPart')

game:GetService('RunService').RenderStepped:Connect(function()
	for _, MODEL in pairs(workspace:GetChildren()) do
		if MODEL:IsA('Model') and MODEL:FindFirstChild('DummyBot') then
			humrp.CFrame = CFrame.lookAt(humrp.Position, Vector3.new(MODEL:WaitForChild('HumanoidRootPart').CFrame.X, humrp.CFrame.Y, humrp.CFrame.Z))
			task.wait()
		end
	end
end)

I tried to make up some solutions, but it would just make the player more buggy. (Such as changing the position of the HRP’s.)

Ideas on how I can improve this so the enemy moves smoothly will be needed. Thank you.

1 Like

My fault for not explaining, the scripts that i added in the post are for making the CFrame the same as the other characters HRP so they dont try and turn around and look crazy.

(The scripts are for the characters to face eachother.)
I can provide a video for you to show what I am talking about.
robloxapp-20220801-1239399.wmv (497.5 KB)

Yes, and for the enemy to constantly look at the player too.
I apologize if the video is buggy!

The scripts went inside of startergui.
They also check for an enemy and make sure its in the workspace, then check if it has a BoolValue called “DummyBot” so they know its an actual bot the player can look at.

The issue is that the enemy is not moving smoothly, and i think it is due to the scripts that i provided in the post. I wanted to see if anyone can improve it so the enemy can move smoothly and not buggy.

Here is the move script:

wait(10)

humanoid:MoveTo(Vector3.new(workspace.Block2.Position.X + 6, workspace.Block2.Position.Y, workspace.Block2.Position.Z))

That is apart of what I am saying, I want the player to move smoothly when walking or running. Its not doing that at all.

When the enemy moves, the enemy is not moving very smoothly and bugging out.

I’ve tried this and its worse, the problem might be with the CFrame, but I dont know how to fix this at all.

Could you show me a video of you and the dummy facing eachother please? To record, just go to the view tab and search for “Video Record” then click it to record when inside the game.

If you couldn’t get a video, maybe make the game public so I can try it out and see if its what I want?

Yes, this is what I want for my fighting game!

A code sample would be appreciated man.

So what I got out of this is that the BodyGyro should make the character move smoothly, right?

I want to experiment with BodyGyro, so thats why I am asking this question.

What do you mean by smoothly. Like does it stutter or stops for a bit?

Yeah. The movement for the enemy would usually stop and not fully move to the position of where i want it to go. the enemy would also bug out a lot and go into the floor.

I was thinking it was because of the orientation scripts that were provided in the post, and it turned out to be that.

Now I am trying to figure out how to improve the orientation scripts so the enemy can move smoothly.

This is the script for the movement, and it works perfectly fine.

wait(10)

humanoid:MoveTo(Vector3.new(workspace.Block2.Position.X + 6, workspace.Block2.Position.Y, workspace.Block2.Position.Z))

Its just that the orientation scripts in the post would interfere with this moving script, making the enemy move not smoothly and glitch out anywhere.

I dont know if this can help but ill leave it anyways. Network Ownership

Try adding this line at the top part for your movement code:
YourNPCModel.PrimaryPart:SetNetworkOwner(nil)

I saw a video with a similar issue and it helped

1 Like

I have another question, why did you put math.huge in the Y section of gyro.MaxTorque = Vector3.new(0,math.huge,0)?

By the way, to clear up some confusion, I am making a 2d game. So Its kind of hard to make the NPC move.

Alright, so im coming back after 2 days of thinking and want to know how to use AlignOrientation. I would appreciate a simple explanation from anyone who knows what it is!

I don’t know much about AlignOrientation, but you can try searching it up. Here’s a devforum article to get you started:

1 Like