Predictable "Random" Generator

Get help using Construct 2

Post » Wed Apr 12, 2017 12:19 pm

Hey there

I'm looking for a way (basically an algorithm) which is 100% predictable, yet shall free as random as possible.

Unless you guys have a better way to achieve what i'm looking forward to:

It's an online multiplayer environment.
Which means it's important that the HOST handles the actual calculation of where and what the players are shooting.
This means that hit detection all happens on the host side.

I don't want to sync every single shot with the player, because the delay is way too big, which means it won't feel responsive for the players when shooting. (the other bad part about this is that i have to sync a lot more data)

I have already a system which sets a specific accuracy depending on your current wielded weapon.
And as of now, this system works pretty good for a non-online environment by randomly changing the accuracy.
But what the players are getting displayed is not what's actually happening, so while they might think they've hit an enemy, they might have missed it.


Here an example with a shotgun with a lot of random projectiles
(This is a custom projectile system i've created on my own since the bullet behaviour doesn't work for realistic-fast projectiles and fail on the collision part)
What the Player sees:
Image

What the Host calculates:
Image

I want to keep this accuracy system, or at least something similiar. Otherwise it's not going to be fun if every shot hits the exact spot you're aiming for. But i also want to display the bullet direction accordingly to what's actually happening on the host.
The system calculates random directions and random distance for each projectile.


My idea now is to have a specific algorithm which will always get the same results, on host and clients without the need to sync the actual bullets all the time. (Basically predictable "randomness")
Which then runs on each players system and the host. The one on the players side of course will only display the projectiles while the host does the actual hit detection. But the idea is that both, the host and all peers run the same algorithm so they show the same projectile directions while still varying with each shot.

This might not be 100% reliable since some bits may get lost on the host side (not triggering a shot), so maybe i could sync the current algorithm state every ~30 seconds for each player to correct that.


How would you handle this? Maybe an entirely different approach?

And if you think the idea might be somewhat solid, are there any specific algorithms i could use?



Thanks for reading :)
Last edited by Everade on Wed Apr 12, 2017 1:28 pm, edited 2 times in total.
B
40
S
8
G
3
Posts: 159
Reputation: 3,019

Post » Wed Apr 12, 2017 12:59 pm

On SHOTGUN_PELLETS created | Set SHOTGUN_PELLETS.Bullet.Angle to PLAYER_GUN.Angle + random(-5,+5)

Modify the random range to your liking.
Image Image Image
B
31
S
11
G
27
Posts: 748
Reputation: 17,093

Post » Wed Apr 12, 2017 1:24 pm

If you read the entire topic then you would notice that i have a similiar system already.
My projectile system is entirely custom and generates a line which stretches over time for proper collision detection with fast-speed projectiles.
The projectiles are already generated entirely random, however only on the host part.

The question is now how to handle it within an ONLINE multiplayer environment, to get the same results on HOST and PEER without syncing the data from the HOST to the PEERS since syncing the projectile data would mean that it won't feel responsive for the PEER.

If i sync the data, that means that you will send your shooting input to the server, the server calculates the projectiles and then sends the information back to the PEERS.
This takes quite a while especially with higher latency and means that once a PEER (player) presses the shoot button, it will take some time to actually display the shot. To prevent that my goal is to directly display the shot (only display, not doing anything further since the host will detect actual hits later on), but it shall display the actual correct angle and distance the same as the host will calculate it.
B
40
S
8
G
3
Posts: 159
Reputation: 3,019

Post » Wed Apr 12, 2017 1:55 pm

You could pre-generate 'random' values (angles) on the host and he sends them to the clients. The client always pulls a 'random' value from this array, and as values get low, send the next batch on 'random' values.
ImageImageImage
B
71
S
22
G
241
Posts: 3,734
Reputation: 134,494

Post » Wed Apr 12, 2017 2:17 pm

B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Wed Apr 12, 2017 2:50 pm

To prevent that my goal is to directly display the shot (only display, not doing anything further since the host will detect actual hits later on), but it shall display the actual correct angle and distance the same as the host will calculate it.


The peer still has to tell the host they have shot, correct? So, why not get them to calculate the angle and send that to the host at the same time? There's no need for the host to do all the calculation.

That way the peer doesn't have to wait for a reply, they can show the shot straight away, and then they only have to wait for the result.

The host can still broadcast for the other peers to fake the shot, but the delay for them isn't important since they aren't the ones who shot.
Find all the Construct 2 games that were on Steam Greenlight here
B
33
S
9
G
7
Posts: 451
Reputation: 6,782

Post » Wed Apr 12, 2017 3:16 pm

@OddConfection
Calculating such important things on the host is pretty much the basics about online games.
You don't want the peer (player) to tell the host how he shoots.

If you do that, you can easily cheat by let's say triggering 10k bullets in 1 second into any direction and the host will be like *ok let me kill everyone*
That's not how you want to build any multiplayer game unless you don't care about cheating.

All the peer does is sending key strokes, and that's it, anything else is being handled by the host.
So if you press the "shoot" trigger 10k times in 1 second, the host will still only trigger 1 shot if handled properly.

In this particular case i could maybe let the peer handle at least the angle, although i guess that could be abused as well but it wouldn't be too bad.
But handling the distance for instance as well would mean that players can get full control about how far their flamethrower reaches and so on.

@99Instances2Go
First time hearing about this.
So that means it's calculated randomly using the fix seed values and i shall sync the seed values between the peers?
Sounds like in the end i would still have to sync all data so it wouldn't be responsive unless i use the idea mentioned by blackhornet

@blackhornet
Very interesting idea, i may give it a try.
Although i guess it could get a little bit complicated since i will have to sync data to each single player objects on his own.
That means there will be a lot of data which needs to be synced.

I may take a closer look at this.


Thanks everyone for your first feedback!
B
40
S
8
G
3
Posts: 159
Reputation: 3,019

Post » Wed Apr 12, 2017 3:20 pm

Seeded random.
viewtopic.php?t=63543&start=0

Count the shots.
Image ImageImage
B
169
S
50
G
174
Posts: 8,325
Reputation: 110,794

Post » Wed Apr 12, 2017 3:38 pm

Seeding is the simpler mechanism (compared to my suggestion). Seeding the algorithm with the same seed, will produce the same results, so the host only needs to send the seed once to the clients. From then on, all random numbers will be in the same order. This is usually a bad thing, so you seed with another random number (like the time/date), but in your case you want to take advantage of this.
ImageImageImage
B
71
S
22
G
241
Posts: 3,734
Reputation: 134,494

Post » Wed Apr 12, 2017 3:49 pm

@Everade

Yeah, I'm not saying give the peer full control, just let them do relatively trivial things like append an angle when they send the keystroke/command to shoot, to improve responsiveness for the peer.

You can add in a check on the host side to make sure it's a valid angle, and if it's not then the Host can either ignore the shot completely or generate a new valid angle.

Is your Host a non-player? Because if they are a player and you're worried about a peer cheating by sending an angle, what do you think the host player could get away with?
Find all the Construct 2 games that were on Steam Greenlight here
B
33
S
9
G
7
Posts: 451
Reputation: 6,782

Next

Return to How do I....?

Who is online

Users browsing this forum: brunopalermo and 51 guests