Client/Server and updating npc's

Blitz3D Forums/Blitz3D Programming/Client/Server and updating npc's

Ferret(Posted 2013) [#1]
The server is written in BMax and the client in B3D.
The client uses physics to move the player and npc's.

I can move the npc's from the server but don't know how to keep track of there position.
Physics are aplyed on the client, there is no physics simulation on the server so the server has no idea where the npc will end up.

One idea i have is asking random clients for npc updates.

Any other ideas on how to do this?


Blitzplotter(Posted 2013) [#2]
You could try looking at this:

http://www.blitzbasic.com/codearcs/codearcs.php?code=2789

Its been ages since I wrote it, but it was a progression from code Wings did a few moons ago. The Server basically maintains x & y co-ords of where every 'client' is and pumps out where each client & other clients are with every communication from a client.

Quite a tough topic though, I gave up on networking stuff ages ago.


RemiD(Posted 2013) [#3]
What i would do is use a structure like this :

Client program :
Repeat
GetInput()
Logic1()
Send()
Receive()
Logic4()
HideShowMeshes()
PlayAnimations()
Render3d()
Render2d()
HUD()
GUI()
Flip()
PlaySounds()
Until()

Server program :
Repeat
Receive()
Logic2()
Collisions()
Physics()
Logic3()
Send()
Until()

In Logic1() the client program only calculates the state of the user and his orientation depending on the new input, his previous state, his previous orientation.

By state i mean for example :
IsIdle
IsWalkingForward
IsWalkingBackward
IsJumping
IsFalling
IsLanding
etc...

Each state illustrating a movement + an animation.

Then, the client program sends the state and the orientation to the server program.

Depending on the state and the orientation of each user, the server program is able to calculate the movement, the collisions detection and response, the bodies behaviors of all entities.

Then the server program sends the results (state, orientation, position) to each client program and the game will be the same on all machines.

Also if there is a packet sent by a client program which is not received by the server program, this is not really important because the server program being able to calculate the movement and behavior of each character with his state, if a packet is not received, the server program can use the last known state and orientation to continue to update the game.

So, i suggest to calculate the state, orientation, movement, colliders collisions, bodies physics, on the server program but only for entities which can affect others entities (characters, projectiles, weapons, doors, traps, etc...) and to calculate the state, orientation, movement on the client program for entities which can't affect others entities (particles, effects, etc...)

That's how i plan to do it for one of my project.


Matty(Posted 2013) [#4]
What sort of game is it? If it is an action game that would be done much differently than if it is a slower paced game....


Ferret(Posted 2013) [#5]
The game is a online rpg/fps.

Getting npc position updates from random clients seems to work.


MCP(Posted 2013) [#6]
Why random? Some clients may be asked for frequent updates, others rarely. Wouldn't it be better to ask each client for an update in rotation?


Ferret(Posted 2013) [#7]
Good point!

Rotation would be better, it will even the load nicly bewteen clients.
I think it will be more accurate too.

Thx!


SabataRH(Posted 2013) [#8]
This is an odd way of doing online physics.. your server should handle the initialization of a physic object them dispurse the data to clients in range.


Ferret(Posted 2013) [#9]
The server sends a move message to a npc with the angle and force.
The clients use newton physics to aply the force.
Then the server asks a client for an update.

How else can the server keep track?


RemiD(Posted 2013) [#10]
The server must manage the calculation of movements, rotations, collisions, physics, then send the results (position + orientation of each entity) to the client programs. (except for unimportant entities which have no impact on the world, like particles, effects, and in this cases you can send a simple message and manage the movement, rotations of the particles/effects on the client program)

If you don't do it this way, or in a similar way, the game will not be the same on all machines.

I thought my previous post was clear about that.

Now of course you do what you want, but there are not hundreds ways to have the same world on all client programs... The way i use is to send the input of the client programs to the server program and let the server program do the calculations, the client programs then display the results.