Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how do i fix this problem while making a npc ai and using body gyros ?

Asked by 3 years ago
Edited 3 years ago

Please provide more explanation in your question. If you explain exactly what you are trying to accomplish, it will be much easier to answer your question correctly.

im making a npc ai, and im having a problem that one of the npcs works perfectly fine and the other one just spins like crazy, im using body gyro but it doesn't seems to work ?

here's my code

local crocs = true
local cro = true
local cr = false

local function sue()
    if cr == true then return end
    local timeo = math.random(1,8)
    wait(timeo)
    cro = true
    cr = false
end

function lookAt(chr,target) --assume chr is a character and target is a brick to look towards
    if chr.PrimaryPart then --just make sure the character's HRP has loaded
        local chrPos=chr.PrimaryPart.Position --get the position of the HRP
        local tPos=target.Position --get the position of the target
        local modTPos=Vector3.new(tPos.X,chrPos.Y,tPos.X) --make a position at the target, but with the height of the character
        local newCF=CFrame.new(chrPos,modTPos) --create our CFrame
        chr:SetPrimaryPartCFrame(newCF) --set the HRP's CFrame to our result, thus moving the character!
    end
end

script.Parent.Target.Changed:Connect(function()
    if script.Parent.Target.Value ~= nil then
        crocs = false
        local target = script.Parent.Target.Value
        local myhuam = script.Parent.Humanoid
        while crocs == false do
            wait()
            sue()
            script.Parent.HumanoidRootPart.BodyGyro.CFrame = CFrame.new(script.Parent.Torso.Position - Vector3.new(0,script.Parent.Torso.Position.y,0),target.HumanoidRootPart.Position - Vector3.new(0,target.HumanoidRootPart.Position.y,0))
            --script.Parent.HumanoidRootPart.BodyGyro.CFrame = CFrame.new(script.Parent.Torso.Position - Vector3.new(0,script.Parent.Torso.Position.y,0),target.HumanoidRootPart.Position - Vector3.new(0,target.HumanoidRootPart.Position.y,0))
            cr = true
            local move = math.random(1,3)
            if cro then
            if move < 3 then
                    local moto = math.random(-3,3)
                    local offset = Vector3.new(moto,0,-8)
                local pos = target.Torso.CFrame*CFrame.new(offset).Position
                myhuam:MoveTo(pos)
                end
            end
            if not cro then
                if move == 3 then
                    myhuam:MoveTo(target.Torso.Position)
                end
            end
        end
    else
        crocs = true
    end
end)

and here's a gyazo gif of the problem

https://gyazo.com/950c7d5d8dea6f83aee73946b4e345dc

the MaxTorque of both body gyros are 0,10000,0 the P is 3000 and the D is 500

0
I'm not too familiar with ai, but maybe you should try upgrading the dampening value mariohead13 129 — 3y
0
https://www.youtube.com/watch?v=XJ10fJEit-I watch tis help you make npc lehoaiquoc248 23 — 3y

Answer this question