#after a few loops, enemy goes in a random direction instead of towards the player

1 messages · Page 1 of 1 (latest)

cinder delta
#

what it says on the tin
(this time with semi-readable code!)

#

local plr = game:GetService("Players").LocalPlayer
local rs = game:GetService("ReplicatedStorage")
local enemy = script.Parent
local event = enemy.Parent.events.spawn
local DEFAULT_STEP = 20
local DISTANCE = 128
local step = nil
local cam = workspace.CurrentCamera
local exposure = 0
step = DEFAULT_STEP

function stop()
    step = DEFAULT_STEP
    event:FireServer("scapegoat")
    enemy.Parent = rs.Entities
    enemy.BillboardGui.ImageLabel.Rotation = 0
    enemy.Sound:Stop()
    print("go away")
end

game:GetService("RunService").RenderStepped:Connect(function(delta)
    
    if enemy.Parent == workspace.entities then
        if enemy.Sound.Playing == false then
            enemy.Sound:Play()
        end
        
        local target = plr.Character.PrimaryPart or plr.CharacterAdded:Wait().PrimaryPart
        local x = target.Position.X*(delta/step)
        local y = target.Position.Y*(delta/step)
        local z = target.Position.Z*(delta/step)
        
        
        enemy:PivotTo(CFrame.lookAt(enemy.CFrame.Position, target.Position))
        enemy:PivotTo(enemy.CFrame * CFrame.new(0, 0, -1))
        
        enemy:PivotTo(CFrame.new(enemy.Position.X-x, enemy.Position.Y-y, enemy.Position.Z-z))
        
        step *= 1.1
        
        if step > 50 then
            step = 50
        end
        
        local pos, visible = cam:WorldToScreenPoint(enemy.Position)
        local center = cam.ViewportSize / 2
        local mag = (Vector2.new(pos.X, pos.Y) - center).Magnitude
        
        if visible and mag < center.Y then
            enemy.BillboardGui.ImageLabel.Rotation = math.random(-15, 15)
            exposure += 1
            print(exposure)
            
            if exposure >= 30 then
                stop()
                exposure = 0
            end
        end
        
    end
    
end)

#

pt 1

#

pt 2:

event.OnClientEvent:Connect(function(enem:string, switch:boolean)
    local angle = math.random() * 2 * math.pi
    
    if enem == "scapegoat" then
        if switch == true then
            local target = plr.Character.PrimaryPart or plr.CharacterAdded:Wait().PrimaryPart
            local cframe = CFrame.new(target.Position) * CFrame.Angles(0, angle, 0) * CFrame.new(0,0, -DISTANCE)

            print("goating it")
            enemy.active.Value = true
            enemy.CFrame = cframe
            enemy.Parent = workspace.entities
        end
    end
     
end)```
#

serverside entity code if yall need it:


local rs = game:GetService("ReplicatedStorage")
local entityEvent = rs.Entities.events.spawn
local furthest = rs.furthestRoom

local main = coroutine.create(function()
    print("you DIDNT forget to resume the coroutine like an idiot didnt happen")
    while task.wait() do
        if furthest.Value >= 13 then
            local active = rs.Entities.scapegoat.active
            rs.dialogue:FireAllClients(1, Color3.fromRGB(255, 0, 0), "WICKED")
            while task.wait() do
                local clock = math.random(2, 5)
                task.wait(clock)
                print(clock)
                if active.Value ~= true then
                    local d20 = math.random(1, 20) -- roll to kill reese
                    print("rolling 1d20 to spawn")
                    if d20 >= 13 then
                        print("its here. it rolled a " .. d20)
                        active.Value = true
                        entityEvent:FireAllClients("scapegoat", true)
                    else print("looser " .. d20) end
                end
            end
        end
    end
end)

entityEvent.OnServerEvent:Connect(function(p, enemy:string)
    print(enemy)
    if enemy == "scapegoat" then
        local active = rs.Entities.scapegoat.active
        entityEvent:FireAllClients("scapegoat", false)
        active.Value = false
    end
    
end)

coroutine.resume(main)```
plush lynx
#

give more information, like what is the environment of the game, what you doing and stuff

#

It's probably an error in your math, try checking what are the maths results and check if they should be like that

#

and where exactly is the thing I should be looking for?

#

And it may be because of a floating point error

#

like 1.03839083932367

#

i just spammed and the last two number were 67 lol

#

wa

plush lynx
#

@cinder delta

cinder delta
#

AH

#

sorry uh

#

i think i was kinda wrong maybe?? still weird tho

#

it does eventually go towards the player it just

#

goes in a random direction at first

#

its weird

#

anywho its like

#

uhh

#

lemme record something

cinder delta
#

its like a doorslike

#

leaning a bit more into the sjm

#

aspect??

#

randomly genned rooms etc which have a diff problem which i mightve fixed idk i havent checked

#

the enemy is this floating goat head thing

plush lynx
#

I dont have the niche knowledge of knowing SJM, what does SJM stand for?

cinder delta
plush lynx
#

what is that???

cinder delta
plush lynx
#

Ohhhhh

cinder delta
#

what doors is mainly inspired by

plush lynx
#

the cardboard cut-out ghosts oohhh

#

and the creepy guy who moves when you not looking

plush lynx
#

nicorocks555

#

I have more niche knowledge

#

nico WAS inspired by that

cinder delta
#

oh

storm trellisBOT
#

studio** You are now Level 3! **studio

cinder delta
#

damn

#

stuf

#

stfu*

#

i havent played doors in a good bit

#

i was half right

#

its inspired by extension of rooms

plush lynx
#

nah you were 1/4 right