Affichage des articles dont le libellé est physics. Afficher tous les articles
Affichage des articles dont le libellé est physics. Afficher tous les articles

mercredi 8 juin 2016

Unity : Shimstar ; reloaded

OK let's try to create a multiplayer space game with 6 degrees of freedom.

I am not sure to follow the right way to create a game from scratch, I will write articles depending of what I consider to be important to know to create a multiplayer game, with physics.

SkyBox


Because, I like to be in the atmosfear, I ve created a skybox using SpaceScape to grab 6 textures.

I create into a folder, named Materials a new Material called skybox. In the inspector, choose the shader (skybox/6 sided)


Next try to add your 6 images to have in the preview your skybox.

Now you can go to the top menu "Window", and choose lighting, to make your new material effective to your scene :

Modify light configuration, to have an ambient light to light your object into the scene.


Networking in Unity

A game is at first defines by different scene. A player will play into one scene, and can travel scene to another scene.
In a configuration of one server, and multiple client connected, you will have a server running for each scene you will create.
The client will loadLevel and connect to the server it needs.
Server must have authority on physics, and will receive input from client, and broadcast results to all client who needs it.
You don't have a global server which manage a world with subscene. It is important to understand this.
Indeed, you will to manage to connect to a scene, and to disconnect from the scene, to connect to another scene running elsewhere (different IP, or different port).

In Unity, each object of the scene, can have multiple component:
  • mesh
  • material
  • scripts
You can associate as much of script you need, to manage behaviour of the object.
For example, you will have 3 scripts:
  • network identity : standard unity script which provide an unique network identity
  • network transform : standard unity script which manage the data transfer of position and rotation of the object
  • your behaviour script : custom script, with your specific fields, and function to manage custom behaviour
Unity will manage network behaviour on object possessing networking script.

Next Step


I will try to describe enough in details the different mechanism, during construction of the game.

I will show you how to manage a connection scene, and connect to a server.

After that, I will show you how to manage physics through networking.







vendredi 8 janvier 2016

Networking : day 3 : torque

After moving forward, next step is to rotate on 2 axis (I choosed 2 for more convenient, I don't like roll :p).

As seen before, the keyboard input are given on client side, and the physics is managed on server side.
So the input must be treated on remote, and the modification value done on server.

First, create input in project settings : using QD and ZS.













Next, we will in pawn blueprint, create an addTorque server event (custom event), running on server, with a vector in input.



 Now we can react at leftright event, and calculate the vector to apply torque



Notice the switch has autority... It is keyboard input, so we have to use remote activity.
 And now, we have to apply torque server side



I think switch has authority is not necessary here, it is more convenient to show example...

Finally, we will catch updown event, to pitch the spaceship


 Done...

For now, you can speed up to go forward, apply torque to turn right/left, or up/down.

Because you are using physics, reaction on bouncing, will be quite realistics

mercredi 6 janvier 2016

networking ue4 : day 2

You got speed management... but now how to move your pawn?

First of all, check that your spaceship is using physics... Go to your pawn blueprint, and look at your static mesh


Check simulate physics, put linear and angular damping at 1, to have enough frictions, to slow your ship in rotation or movement (otherwise it will speed very highly, and rotate very quickly... :p)

It is a space game, I disabled gravity.

Physics is important  on server, but totally unusefull on client, so desactivate it, on begin play event.



As you see you choose remote on switch autority, to disable physics simulation only on client side.

I am using physics because, I wish to have bounce behavior, collision, and so on. So I will add Force to my mesh, to make it move forward.
I will do this on server



And this is it, your pawn is moving. But client didn't see the move...
I created a custom event, I will use to broadcast the new position/rotation to client. I give to it, vector and rotator as parameter.
Multicast == broadcasting


On server side, I will get my rotation, and location, and give it to my custom event. Custom event will run on client side, I set to my mesh, the new position and location.


Global schema is this