War Battles Multiplayer Addition

Hello!
Very new to Defold and wanted to explore the multiplayer capabilities. I decided to add on to War Battles since that’s the first tutorial I completed.

Here’s the repo: GitHub - alteredorange/war-battles-multiplayer: War Battles Multipalyer

Right now it only syncs the client’s positions (no rocket updates, tanks, etc.). The readme should have all the details you need to try it out. Would love any pull requests and/or suggestions since I’m sure multiple things could be done a lot better :rofl:

One thing would be the synced player movement is still jittery. The relevant code is in the other_players.script file (taken from Britzl’s example Game Object Follow Mouse Cursor at Certain Speed - #2 by britzl):

function update(self, dt)
	update_animation(self)
	local current_position = go.get_position()
	local diff = self.target_position - current_position
	local distance_to_target = vmath.length(diff)
	if distance_to_target > 0 then
		direction = vmath.normalize(diff)
		local distance_to_move = math.min(distance_to_target, self.speed * dt)
		local new_position = current_position + direction * distance_to_move
		go.set_position(new_position)
	end 
end

Thanks!

3 Likes