Multiplayer - Lag compensation for non-player objects?

Discussion and feedback on Construct 2

Post » Tue Aug 05, 2014 8:34 pm

I’m currently attempting to add multiplayer to my game, which has a lot of NPC bots/AI agents/whatever you want to call them. The agents use the same object type as the players-- anything a player can do, an AI Agent can do, which includes moving in all directions.

From what I can gather, LagCompensateX and Y return the position coordinates for objects that were used in the “Associate object with peer” command. Does this mean that lag compensation would not be possible with non-player objects such as my AI Agents? Is there something I’m missing here? (I'm still fairly new to using the multiplayer plugin)
(M.A.D. are my initials. I'm not the least bit angry, really!)
@madguy90
B
11
S
4
Posts: 41
Reputation: 1,671

Post » Thu Aug 07, 2014 5:04 am

Have you read alllll the multiplayer tutorials (I believe there's 4)?
Not an easy read, by any means, but I'm pretty sure what you're looking for is in there.
B
86
S
43
G
71
Posts: 601
Reputation: 43,619

Post » Thu Aug 07, 2014 5:22 pm

Indeed I have-- I'm actually about 1.5 weeks into grafting multiplayer into my game :) Lag compensation is covered here:
https://www.scirra.com/tutorials/915/mu ... ame/page-7

Unfortunately I think I've hit a snag. To the best of my understanding, LagCompensate is only able to deal with objects associated with peers. Which is fine if you're doing a game where the player characters are the only moving objects with collision detection, but not so great if you want to have, for example, fast-moving AI-controlled enemies.
(M.A.D. are my initials. I'm not the least bit angry, really!)
@madguy90
B
11
S
4
Posts: 41
Reputation: 1,671

Post » Fri Aug 08, 2014 11:34 am

Hi! I am working on a multiplayer game right now and added controls for peers and hosts. (copied many parts from the game tutorial and edited a few)
I want the players to constantly shoot bullets when they hold down Mousebutton 1 and the host creates the bullets (synced object). Do they need some kind of lag compensation like in the example or is this only viable when using things like lasers/instant hit projectiles (like in the example game)?

But if you should use it how is a good way to implement it for multiple bullets which may travel a while before they hit anything?
B
54
S
16
G
6
Posts: 719
Reputation: 9,207

Post » Fri Aug 08, 2014 1:57 pm

Recently I was working on a realtime multiplayer game too but I hit the same issue. I decided to rewrite the game to a less realtime type; ie it's turn based now, with limited time during each turn. Now both bots and players have 30 second per turn to do some actions. Hopefully you come up with something, I'm really looking forward to it
B
11
S
4
Posts: 11
Reputation: 1,004

Post » Fri Aug 08, 2014 2:57 pm

I'm also exploring multiplayer (4-player FFA with projectiles, moving platforms, etc). Reading here makes me think a "best practices" tutorial would be helpful. Beyond the explanation of the MP features in the manual - more about 'when to use / not use this feature'. Perhaps from Ashley & co (though I assume their hands are full!) or perhaps a compilation of findings from those of us building MP games.

In any case, good luck to all of you!
B
21
S
5
G
3
Posts: 66
Reputation: 2,848

Post » Fri Aug 08, 2014 5:18 pm

@Bl4ckSh33p I'm also using non-hitscan bullets, but I've not fully decided how I want it to work yet. I'm considering having them be completely separate, non-synced entities on each player's screen, and only dealing with collisions on the host's screen (so that there's no delay when the player hits the Fire button, I think that would kind of suck). I think in both my case and the case that you described, having lag compensation would be ideal, since there will always be a delay getting the information to the host after the peer presses the Fire button.

There are probably some halfway-decent workarounds. Maybe if each moving object pushed their current position into an array every tick, and then we used a peer's latency (PeerLatency expression) to determine how far back in the array we should look to find where the collision check should occur. I haven't tried that and it might work really crappy, just throwing it out there.
(M.A.D. are my initials. I'm not the least bit angry, really!)
@madguy90
B
11
S
4
Posts: 41
Reputation: 1,671

Post » Sat Aug 09, 2014 8:55 am

I thought about trying this, too @Madguy.

But I have a problem with syncinc. I set it up the same for some objects but only half of them appear on the peers.
e.g. Ships (players) are synced fine, same applies to the laser shots/bullets the server creates but the on collision spawned explosion (has the same sync object action like the other objects) never appears on the peers.

Is there a way to check whats wrong with the synced objects or see if they are really synced?

Here is an example:
FXExplosion is never showing up on peers, only on the host. But why? :?:
The only difference I can think of is the FadeIn behavior set to disabled by default, set to fade out over 1 sec when activated. And its activated after Animation:Default is finished to remove the object. But that should not break syncinc?
Image
(laser is a bullet created every 0.5sec when holding down mouse1 and synced to everyone. Maybe this is too much to sync and bullets appear "laggy" sometimes even if I have only 30-60ms pings. I thought about creating them on the peer AND host but just check the hosts version for collisions but dont know if this would work.)

As far as I can see from the ghostshooter example the lag compensation works for instant hit bullets/lasers - but does this work for bullets which fly a while before hitting anything? I dont know if it works or how to set it up. :/
B
54
S
16
G
6
Posts: 719
Reputation: 9,207

Post » Sat Aug 09, 2014 7:19 pm

As far as I can see from the ghostshooter example the lag compensation works for instant hit bullets/lasers - but does this work for bullets which fly a while before hitting anything? I dont know if it works or how to set it up. :/


Here's a simple way to do it: If a bullet is on the screen, do a collision check between the bullet and the lag-compensated version of the object on every tick. Alternatively, you could perform the check only if the bullet is already within a certain distance of the object.

As for why certain objects aren't appearing, it's hard for me to say at the moment-- I haven't been attempting to sync objects that are quick to appear and disappear (lasers, explosions, bullets, etc.). Did you set up an "On Created" event for them? Seems like you might be able to fix the issue with some actions in an event like that, or at least print out some text to ensure that the object is actually getting created in the first place.
(M.A.D. are my initials. I'm not the least bit angry, really!)
@madguy90
B
11
S
4
Posts: 41
Reputation: 1,671

Post » Sun Aug 10, 2014 6:25 am

Thanks for your description and suggestion for the synced object. I have a "On Created" event in the Peer group to play a sound effect. For some other things like sound on collision I used a send message action and the peer has a "on message X: Play Sound" event because collisions dont work on the Peer (as far as I can tell after some tests).
I will try to use the lagcompensate coords for collisions (but dont know how, yet).

The lasers are created every 0.5 sec and are all created on the Peers (but they appear a bit laggy even if the latency/ping is only 0-20). I will try to debug it with "On Created" (the same happens in another game where a laser object (one long shot like in the ghostshooter example) is never synced).

If you like you can test the current version here: http://www.playbird.at/sites/Bl4ckSh33p ... index.html
(the Server is not running always because I use my local computer for it)
B
54
S
16
G
6
Posts: 719
Reputation: 9,207


Return to Construct 2 General

Who is online

Users browsing this forum: Solomon, Studio Mercato and 2 guests