-- monster_behavior.lua

function updateMonster(dt, x, y, z, visible, isPlayerLooking, playerX, playerY, playerZ, score)
    local position = {x = x, y = y, z = z}
    local playerPosition = {x = playerX, y = playerY, z = playerZ}

    if not visible then
        -- Move towards player
        local direction = {x = playerPosition.x - position.x, y = playerPosition.y - position.y, z = playerPosition.z - position.z}
        local length = math.sqrt(direction.x^2 + direction.y^2 + direction.z^2)
        if length > 0 then
            direction.x = direction.x / length
            direction.y = direction.y / length
            direction.z = direction.z / length

            local baseSpeed = 2.0
            local speedIncreasePerScore = 0.2 
            local speed = baseSpeed + speedIncreasePerScore * score
            position.x = position.x + direction.x * speed * dt
            position.y = position.y + direction.y * speed * dt
            position.z = position.z + direction.z * speed * dt
        end
    end
    
    -- Return updated position
    return position.x, position.y, position.z
end
