Predictable "Random" Generator

Get help using Construct 2

Post » Wed Apr 12, 2017 9:07 pm

Sometimes, it pays off to not be too strict about authoritative host when certain requirements need to be met. Bullet spread is definitely a classic problem for real time multiplayer shooters. There are many approaches, for different situations.

1. Fudge the local visual. Example - Counter strike - the bullet holes a player sees doesn't necessarily mean that's where the server decided the bullet actually went, even if they have the same constraints. It is an illusion, but doesn't necessarily affect game play significantly. For a third person view like yours, this works especially well if you have an "accuracy" type system as well, where a bullet passing through a sprite has a percent chance to do damage or "hit". Running with Rifles is a good example. If it is known the enemy has a chance to not get hurt even if it looks like they get hit, they will be more accepting of fudging done due to mismatching host/client visuals.

2. Use a seeded random. A possibility, but not recommended with something as numerous as bullets across multiple peers.... Keeping the order synced sounds like a nightmare to me, but I haven't tried it so I might be wrong.

3. Best for slower projectiles - Have the local input prediction fire off a bullet sprite with 0 angle, and after it receives the actual angle from the host, start correcting the course of the local bullet. The slower the projectile, the less distance it will travel before getting the actual angle, making it not really noticable. There would only be a slight discrepancy near the origin, where the angle has the least impact anyway.

I think for your particular situation you have two best options - just fudge the player's visual feedback and accept that it might not be "real", or allow the peer to be authoritative on the angle of the shot.

An additional nice touch is to have seperate feedback for a host determined "hit", like blood or flashing some other indicator. Then even if it looks like a bullet passes through the enemy, if they don't flash maybe it can look like the bullet went by them (above?). Also if it looks like the bullet missed, but host determines a hit, at least the player will get some feedback that there were hits.

Lastly, the less possible bullet spread the easier it is to fudge acceptably in general, which may be a consideration.
Mistakes were made.
B
49
S
24
G
107
Posts: 1,581
Reputation: 60,303

Post » Thu Apr 13, 2017 11:49 am

@oosyrag
1. I'm fine with it if it's an illusion. But it shouldn't bee too far off.
Since my game isn't going to be competitive (player vs players) it's not so important to be 100% accurate.
But i still want to have some proper visual feedback so in case of weapons which have a really bad accuracy don't shoot into the complete opposite direction, showing a hit but they actualy did not.

Especially if there are smaller fast moving enemies and you try to hit them.

I personally think (as a player) if that happens too much, they blame it on *bad hitbox detection* or network issues or whatever.
The more accurate it is and the more responsive it feels the better for the game and the joy for the players.
And i also don't want to play a game where my visual feedback is always way off.

2. Yea really sounds like a nightmare xD
I'm not sure if this is the best approach. And to prevent too much issues i can imagine that i'm almost forced to send 1 seed per peer, because if they are all shared the possibility that the sequence gets mixed up (delay of shot being triggered due latency)

So that means 1 seed per peer, and to prevent missmatches over a longer time-frame i guess i would have to re-sync the seeds every 30 seconds ~ 2 minutes.

Maybe that way it works out, i will for sure take a closer look at this.

3. I'm actually using realistic real world projectile speeds ~400m/s which is around 266px per tick if running on 60fps with my setting.
Which means that's absolutely impossible for my case :P
Another reason why the official bullet behaviour would never work for me.

Visualy the players will only see a flash-line similiar to the one showed in the picture i've posted.



@OddConfection

I see 1 big problem with that.
Let's say the Peer shoots, and sends the angle to the Host.
The host recieves the angle but assumes that the player was standing at a different position (due movement of the player while shooting)

I don't know if that's going to be accurate enough or if that's going to mean that the shots could be registered at entirely wrong positions.
From host to peer there's the prediction stuff and all that, but what happens if i send this data the other way around?
Is there a way to *sync* the angle together with the actual mouse click sync so the host recieves both data at the same time?

Does anyone have experience with this?


And to your question:
The host is a player.
And i know what that means.
But Construct isn't really made for anything else... is it?
B
39
S
8
G
3
Posts: 158
Reputation: 2,995

Post » Thu Apr 13, 2017 12:49 pm

So that means 1 seed per peer, and to prevent missmatches over a longer time-frame i guess i would have to re-sync the seeds every 30 seconds ~ 2 minutes.

Nope. Use same algorithm to produce noise on both sides. Exchange seed only once.

Say, we use 3D Perlin noise.
Then the noise plugin returns a random value for Noise.Perlin(x,y,z) that is always the same for the same x,y&z, but different for different seeds.

Now you can produce noise by something simple as
(random spread angle) = (random spread angle) + (Noise.Perlin(enemy.x,enemy.y,uncorrected spread angle))

Uncorrected spread angle is, i suppose, an iteration from a base angle (base angle + 3, base angle + 6, base angle + 9, base angle + 12)

Ofcourse, the deviation of the noise must meet you needs. The random (with the same seed) will be exactly (as exact as floating can be) the same on both sides.

You might better of to choose a bigger deviation, and round(them) or floor(them).
B
33
S
18
G
27
Posts: 2,440
Reputation: 20,344

Post » Thu Apr 13, 2017 1:19 pm

Everade wrote:...
The host recieves the angle but assumes that the player was standing at a different position (due movement of the player while shooting)
...
Is there a way to *sync* the angle together with the actual mouse click sync so the host recieves both data at the same time?


Don't Sync clicks/input, use the On Click event to do a Send Message to the Host, with an encoded string or JSON data containing both clickType and Angle, so both arrive at the same time. You can include player position as well in that for verification/adjustment.
Vote for all the Construct 2 games on Steam Greenlight - Find them here
B
32
S
9
G
7
Posts: 444
Reputation: 6,731

Post » Thu Apr 13, 2017 1:33 pm

I'd say one seed per session.
Forget collisions as well. The random number is your percent to hit. Displaying bullets is just aesthetics.
Image ImageImage
B
168
S
50
G
163
Posts: 8,221
Reputation: 105,061

Post » Thu Apr 13, 2017 2:00 pm

@99Instances2Go

Yea i guess i understood how seeds work (at least the basics)

But let's say Peer has some short connection issues while shooting, or simply something went wrong while sending the player input data to the Host.
Now the Peer will display 10 shots.

But the Host only triggered / recieved / noticed 9 shots.

This means that the entire seed sequence will be off by 1 for the Peer for the rest of the game.
Which means all the following shots will be displayed wrong.

I think the chances that this happens is pretty big, considering a fast-paced shooter with multiple players shooting with "realistic" automatic weapons and whatnot. (thousands and thousands of projectiles)
And this is all running through a Peer to Peer connection with normal PCs and normal Internet connections. (not a perfect world)

That's why i'm saying:
To prevent that, maybe it could be possible to re-sync the current state of the seed every 30 seconds~2 minutes or something like that.
(If that's possible, since i've never worked with it?!)


@newt
Collisions will be handled host-side only.
Displaying projectiles can be just aesthetics, but i want them to be as accurate as possible.
Why? Because as a player i want to see when i hit something.
Anything else is garbage.
As i've said before, it does not have to be 100% accurate, so it's fine when there are some discrepancies.
But missing and still killing, or hitting and never killing is bullshit if it happens a lot.
And i want some visual feedback with the projectile flash-line.
I do not plan to only have a muzzle flash and then wait until the server responses if i've hit something or not.
And i do not plan to only have a muzzle flash and then show absolutely wrong information just for the sake of being responsive.

Random number being percent to hit?! I don't get what you mean.


@OddConfection
Never done that, i will take a look at it if i can find something.
Including player position as well would require for some host-side position checks, which i guess could get pretty complicated to achieve.


Thanks again guys!
B
39
S
8
G
3
Posts: 158
Reputation: 2,995

Post » Thu Apr 13, 2017 2:47 pm

"Random number being percent to hit?! I don't get what you mean."

A player either has a shot or does not have a shot, line of site would handle that. The number generated tells you if the shot hit, based on accuracy aka chance to hit, and possibly the damage given.
Image ImageImage
B
168
S
50
G
163
Posts: 8,221
Reputation: 105,061

Post » Thu Apr 13, 2017 4:24 pm

Why don't you use an authoritative server? You could use websockets to transfer the relevant info back and forth?
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,414
Reputation: 4,822

Post » Fri Apr 14, 2017 4:36 pm

@gumshoe2029
Is there any guide on how to do this?
Or what exactly do you mean?

Currently i've built anything within the same construct 2 project.
Which means the first player connecting will become the host (authoritative) while anyone else becomes a peer.

I was already playing with the idea to create 2 seperate Construct 2 projects.
Basically a "dedicated" authoritative Server version (not playable, just handles all the authoritative logic.

And the actual players running the game connect to this version.

The problem on that idea is that it would require tons of these server versions to run on dedicated machines.
And i don't have the resources to accomplish that. Unless i give the players access to this version so they can run it themselfs.

I guess there are other ways using plugins and other 3rd party tools but i have really no idea what nor how that would work out.


In the end i would love to have a server-list so players can join wherever they want, and also to connect directly with their friends (maybe with steam integration).
B
39
S
8
G
3
Posts: 158
Reputation: 2,995

Post » Fri Apr 14, 2017 4:46 pm

Like use a server side program (Python, PHP, Java, etc.) to run the logic for your game. Then communicate with that program via WebSockets. Then your clients would make a request like: "shoot at position x,y" and the server would take that request, apply the randomization at the time of request receipt, and determine if there is another object at r(x),r(y) at the time that the request is received and turn around and push the same results to all clients.

You should be able to do the same thing with an authoritative client, but it seems easier to work in another more robust language than JavaScript.

I can give you a guide on how to setup your own servers and point you to programming resources. I have been hesitant to post a guide on how to setup and run authoritative servers because I don't want to step on Scirra's store. Feel free to PM me though, and I will send you information.
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,414
Reputation: 4,822

Previous

Return to How do I....?

Who is online

Users browsing this forum: Cubus32 and 5 guests