#Problem with lookAt()

1 messages · Page 1 of 1 (latest)

silent ore
#

https://www.youtube.com/watch?v=R78hmD4AwOw
1:20
How can I make a movement system similar to the one in the video? I've been trying some things, and I have a problem with the lookAt(), and that is that the rotation is only updated at the end, if I remove it so that it is not updated at the end (that is, it is constantly doing the rotation), and I also remove the default auto rotation of Roblox to do it manually, then the NPC starts to do strange things, moving teleported. it turns and it moves to the sides, but I can't do it smoothly, any advice on how it should be done in theory?

#
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local actualDistance
local Distance = 30 
local npc = script.Parent
local canBeat = true 
local npcRoot = npc:WaitForChild("HumanoidRootPart")
local npcHumanoid = npc:WaitForChild("Humanoid")

local directions = {
    Vector3.new(2, 0, 0),   
    Vector3.new(-2, 0, 0),  
    Vector3.new(0, 0, 2),   
    Vector3.new(0, 0, -2),  
    Vector3.zero           
}

RunService.Heartbeat:Connect(function()
    --if canBeat then 
    for _, player in pairs(Players:GetPlayers()) do 
        if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
            local char = player.Character
            local root = char:WaitForChild("HumanoidRootPart")
            
            actualDistance = (root.Position - npcRoot.Position).Magnitude
            
            if actualDistance < Distance then
                if actualDistance > 5 then
                    
                    npcHumanoid:MoveTo(root.Position)
                    
                    else
                        canBeat = false
                    --local random = math.random(1, 100)
                    local random2
                    --if random >20 then
                        --random2 = 5
                    --else
                        random2 = math.random(1, 5)
                    --end
                        local moveto = npcRoot.Position + directions[random2]
                        npcHumanoid.AutoRotate = false
                        npcHumanoid:MoveTo(moveto)
                        wait(1)
                        npcHumanoid.AutoRotate = true
                        canBeat = true
                    npcRoot.CFrame = CFrame.lookAt(npcRoot.Position, root.Position)
                end        
            end
        end
    end    
    --end    
end)
gloomy turret
#

or no

silent ore
gloomy turret
#

give me a bit and ill provide u with it

silent ore
silent ore
gloomy turret
silent ore
#

the follow is good, and the auto rotate of roblox do their job

#

but

gloomy turret
#

ill see waht i can do

silent ore
#

when reaches de < 5

silent ore
gloomy turret
#

ill see what to do

silent ore
#

okok

gloomy turret
#

it won't move yet, it bugged out and ill fix it in a bit

gloomy turret
#

I have updated the script, it now uses not so complex mathematics using A* to check for places to head to if the user is behind a wall

#

its dumb yes, but i cant do much as roblox's MoveTo() is stupid

gloomy turret
#

ill make a new 1

#

bc its bad

#

ill fix it and prolly use it later

#

so id suggest going on the dev forum and asking there

silent ore
#

but yeah, english is not my first lenguaje, so sorry if i miss understand, but the follow is not the problem

silent ore
#

this is one i used path fanding

#

but what i want to get