What do you want to achieve?
I have been working a gun NPC for a while, I was able to get the npc to face the target on the y-axis, however it didn’t fully work as expected since I later realized that it also changes based on the targets orientation on the y-axis.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have been trying out various different solutions on the developer forum and with the different methods within CFrame, none of which solve or really helped. Some of the solutions I have tried uses the CFrame.lookAt(), however the parts tend to move infinitely in a certain direction, or set a new position way off from where the npc is supposed to be. If there are any that I may have not considered please let me know. Thank you in advance.
What is the issue? Include screenshots / videos if possible!
Sorry for the low quality video.
The npc can follow the target, but it only follows momentarily, only when you jump it follows. Also through testing, what i don’t understand is why it only follows the target when its unanchored.
This was the code I was using
if math.abs(UpperTorso.Position.Y - root.Position.Y) > 1 then
--print("Player's height is greater than 1")
local leftMotor6 = npc:WaitForChild("LeftUpperArm"):WaitForChild("LeftShoulder")
local rightMotor6 = npc:WaitForChild("RightUpperArm"):WaitForChild("RightShoulder")
local headMotor6 = npc:WaitForChild("Head"):WaitForChild("Neck")
leftMotor6.C0 = CFrame.new(leftMotor6.C0.Position) * CFrame.Angles(-UpperTorso.CFrame.LookVector.Y, 0, 0)
rightMotor6.C0 = CFrame.new(rightMotor6.C0.Position) * CFrame.Angles(-UpperTorso.CFrame.LookVector.Y, 0, 0)
headMotor6.C0 = CFrame.new(headMotor6.C0.Position) * CFrame.Angles(-UpperTorso.CFrame.LookVector.Y, 0, 0)
end
Hello, this is a very annoying issue, as I’ve experienced it multiple times as well. This has something to do with “retargeting”. It’s a property of workspace and is turned on by default. Turn it off and see if you get any results. If not, then your code is broken. (You can put prints in the if statement and see if the C0s get edited)
Yes, its actually in a runservice.Heartbeat, and its checking the height so that if the player’s on a different level the npc should orientate its arms and head towards the target.
I would move the constants that use wait for child to outside the loop. This will ensure they are not being created each time, which is inefficient and could cause delays. I’m not sure this will work but it will make your code run faster.
Then it is probably is a problem with this part of your code. I’m not very experienced with Cframes but maybe someone else can say what’s wrong with this.