I building a little game with a multiplayer, my problem is when I sending the bullets is there is a lag when it's exceeding the amount about 80.
I using UDP type, my connect code to the server:
udp = socket.udp()
udp:settimeout(0)
udp:setpeername(address, port)
My udp:send of the bullet to the server:
udp:send('%S03'..startX..','..startY..','..bulletAngleX..','..bulletAngleY)
Server: retrieving the bullets and sending them back to the rest of the clients:
elseif code == '%S03' then
local bulleta = string.gmatch(params, "[^,]+")
local sX = tonumber(bulleta())
local sY = tonumber(bulleta())
local dX = tonumber(bulleta())
local dY = tonumber(bulleta())
for i,v in ipairs(clients) do
udp:sendto('%C01'..math.random(120, 200)..','..sX..','..sY..','..dX..','..dY, v['ip'], tonumber(v['port']))
end
end
Client: getting the bullets data and creating them in a table:
elseif code == '%C01' then
local xy = string.gmatch(re, "[^,]+")
local dis = tonumber(xy())
local xStart = tonumber(xy())
local yStart = tonumber(xy())
local xAngle = tonumber(xy())
local yAngle = tonumber(xy())
table.insert(bullets, {distance = dis, sX = xStart, sY = yStart, x = xStart, y = yStart, dx = xAngle, dy = yAngle})
The updating of the x and y cordition of the bullets is happening in the client when he gets the bullets x, y and removing the bullets when they distance are more then 300 pixel from the first position.
But my problem is still that there is lags when I am shooting..