so im setting max torque to math.huge
to get my npc to rotate faster. only problem is he spawns on his side when i join the game instead of upright.
when i set the maxtorque to something between 4000-12000 or something its fine and he’s upright but the rotation isn’t really fast and i want it to be more responsive.
game.Players.PlayerAdded:Connect(function(p)
p.CharacterAdded:Connect(function(c)
-- Variables
local hrp = c:WaitForChild("HumanoidRootPart")
local plrHum:Humanoid = c:WaitForChild("Humanoid")
local runanim = npc.run
local runAnimTrack = catHumanoid.Animator:LoadAnimation(runanim)
local connection = nil
local playing = false
-- Create alignorientation to handle rotation
alignOrientation.MaxTorque = math.huge -- Only rotate along the Y axis
alignOrientation.PrimaryAxis = Vector3.new(0, 1, 0)
alignOrientation.Responsiveness = 200
alignOrientation.Parent = catHRP
alignOrientation.Attachment0 = att
alignOrientation.Mode = Enum.OrientationAlignmentMode.OneAttachment
-- Function to smoothly rotate and move backward
local function moveAway()
local distance = (catHRP.Position - hrp.Position).Magnitude
-- If player is close enough
if distance < 15 then
-- Smoothly rotate the NPC towards the player using BodyGyro
alignOrientation.CFrame = CFrame.lookAt(catHRP.Position, Vector3.new(hrp.Position.X, catHRP.Position.Y, hrp.Position.Z))
-- Calculate a point 10 studs backwards and move there
local backwardDirection = (catHRP.Position - hrp.Position).Unit * 10
local targetPosition = catHRP.Position + backwardDirection
catHumanoid.WalkToPoint = targetPosition
catHumanoid.AutoRotate = false
if not playing then
runAnimTrack:Play()
playing = true
print("playing!")
end
else
-- Stop the NPC if player is far
catHumanoid.WalkToPoint = catHRP.Position
--catHumanoid.AutoRotate = true
runAnimTrack:Stop()
playing = false
end
end
-- Connect to RunService to check player's position every frame
connection = rs.Stepped:Connect(moveAway)
plrHum.Died:Connect(function()
connection:Disconnect()
end)
end)
end)