I will make some articles about AI I am building.
I will not use for the moment, tooling set in ue, because I will not have change of behaviour (attack, defense, patrol).
I will for the moment make only one behaviour, and one goal to reach, without modification depending of the situation of the AI.
My goal is to put in space 2 cubes, and to spawn an AI pawn controlled by an AI controller.
The AI will retrieve first cube, and will fly to this one. It will shoot at it, destroy it, next it will change of target, and fire on the second one.
I ve created a pawn, with a static mesh, with physic enabled.
Don't forget to precise that the pawn is possessed by your specific AIController blueprint:
For my purpose, one of the central need I have, it to be able to orient my pawn to my target.
In AIController, I ve defined a variable TargetToGo
and create a function to associate a value to the target
I retrieve all object in the scene which are from class gopoint (my cubes, there are two of them). If actual targetToGo is different of the one retrieve in foreach loop, I affect it, and break the loop.
Quite simple.
Ok, for now, I have a target for my pawn... The difficulty is to know how to orient my ship to the target, to move near it, and shoot at it.
Ue4 gives possibilities through transformation tools, to make world location, in local location relative to the ship.
From my pawn, and target, I retrieve static mesh.
From AI ship, I create a transform object (world transform) and I connect it to an inverse transform location object. This last one is the way to make world location into relative location (transform location does the inverse, relative to world).
In parameter, you give actual world location of the target, and you will have a vector in output.
Now, if you break the vector, y which is a left/right coordinate, and z a up/down coordinate. When z and y are at 0, target must be in front of you.
X value in case of y and z at 0 will be the distance to the target.
X can give you clue, if your spaceship is going to, or going away of. If x is equal to - (distance), you are going away from the target.
You have to make rotation, to make x near from distance, and then re apply torque to reduce y and z to 0
Affichage des articles dont le libellé est unreal. Afficher tous les articles
Affichage des articles dont le libellé est unreal. Afficher tous les articles
jeudi 18 février 2016
vendredi 22 janvier 2016
ue4 multiple level zoning, and architecture
It is important to understand how ue4 works to make a multiplayer game.
A dedicated server runs only one level (physics, replication, ...).
You have multiple possibilities. If all your players are changing of zone at same time, and the zone is loaded only at this moment, your server can change zone, and load it, and the clients will do the same.
One server is enough
But if you wish to have several zone running at same time, you must keep in mind, that you must have one dedicated server per zone.
The client will connect to the server it needs at the moment it wants.
From my side, when client is launched, it is not connected. It shows a level with a tiny scene, and an UI to fill knickname, and a button to connect.
Once player clicks on connect, I send a connection to the first server using IP and port.
it is enough. Once connected, the server will send the level to load, and replicate actors which need to be replicated.
during game, maybe player wish to change zone, to travel elsewhere. I will disconnect to current server, probably load a temporary level, with tiny scene, to wait connection to other server, and then I will connect to a new IP/Port, to reach the new server hosting the level I want to travel to.
Once again, the server will send the name of level to load, and replicate what it needs.
Finally it is quite standard as an architecture, but you don't have choice, it is way to do.
I got a question on instantied zone. I think best way is to have a running server by instance too.
A dedicated server runs only one level (physics, replication, ...).
You have multiple possibilities. If all your players are changing of zone at same time, and the zone is loaded only at this moment, your server can change zone, and load it, and the clients will do the same.
One server is enough
But if you wish to have several zone running at same time, you must keep in mind, that you must have one dedicated server per zone.
The client will connect to the server it needs at the moment it wants.
From my side, when client is launched, it is not connected. It shows a level with a tiny scene, and an UI to fill knickname, and a button to connect.
Once player clicks on connect, I send a connection to the first server using IP and port.
it is enough. Once connected, the server will send the level to load, and replicate actors which need to be replicated.
during game, maybe player wish to change zone, to travel elsewhere. I will disconnect to current server, probably load a temporary level, with tiny scene, to wait connection to other server, and then I will connect to a new IP/Port, to reach the new server hosting the level I want to travel to.
Once again, the server will send the name of level to load, and replicate what it needs.
Finally it is quite standard as an architecture, but you don't have choice, it is way to do.
I got a question on instantied zone. I think best way is to have a running server by instance too.
UE4 packaging
The first times I packaged my game, I was totally afraid by the time it took. on my laptop, it was between 1 and 2 hour, with very lot of steps.
Looking at log, I saw that lot of components was taken in the package, html5, VR, ... and so on, what the hell, I have no needing of all of this.
For information, all this components are standard plugin in ue4 editor. So just go to plugins menu, and disabled all you don't need. your package will be better, and you will package quicker :D
Looking at log, I saw that lot of components was taken in the package, html5, VR, ... and so on, what the hell, I have no needing of all of this.
For information, all this components are standard plugin in ue4 editor. So just go to plugins menu, and disabled all you don't need. your package will be better, and you will package quicker :D
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
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

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
ue4 : networking day1
The aim of my game is to do a multiplayer game, with a dedicated server and clients.
It was sometimes hard to find my way, to understand networking in unreal engine, so I will try to take time to explain different things about networking, and to illustrate what I 've done in my game about the different topic.
If you need, more precise focus, let me know.
First of all, because it is dedicated server, server has control over all things. You have to draw blueprint in same blueprint for case of "server", and case of "client".
It is important to understand this. It is important also to understand what will be managed by server and replicated to client, and what is manage by client.
On client board, you will manage essentially UI, special effects, keyboard/mouse input management...
Server will manage AI, movement, physics, spawning, ...
So every time, you wish to move your pawn, through keyboard input, you will have to send the information to server, which will move the pawn, and replicate/broadcast new position.
Ok with this very few basics...
First, I will show you how to manage increase/decrease speed on my spaceship.
First I create new input in project settings

Next in my pawn Blueprint, I create two variables, speed, and speedmax.
Speed will be replicated. It is an information needed by client to manage UI and FX for example.
Replication is always from server to client.


I ve created next a new custom event in my blueprint. The event receives the new speed, and set the variable with it.
Event must be run on server

Finally, I receive my speed input (through A or W keyboard input), and I manage the increase of speed, and send it to server.

Pay Attention on switch authority. Switch authority allows to run what is after on server, or client. Here, because it is a client input, I have to manage following on client. So I choose remote.
If it was an event about collision for example, I must switch on authority, to manage it only on server.
If you don't use this switch, it will be run on both (client and server), and you can have strange behavior or maybe error. For example, if you manage to update an UI, on dedicated server, you will have errors, because there is no window for server.
Here, you will manage keyboard input to increase speed, and send the update to server.
Server will update speed variable, and because of that, the update will be replicated to all client.
To do better, you can send the input to server, which will manage the different test case, to be sure and guarantee no cheat :D
It was sometimes hard to find my way, to understand networking in unreal engine, so I will try to take time to explain different things about networking, and to illustrate what I 've done in my game about the different topic.
If you need, more precise focus, let me know.
First of all, because it is dedicated server, server has control over all things. You have to draw blueprint in same blueprint for case of "server", and case of "client".
It is important to understand this. It is important also to understand what will be managed by server and replicated to client, and what is manage by client.
On client board, you will manage essentially UI, special effects, keyboard/mouse input management...
Server will manage AI, movement, physics, spawning, ...
So every time, you wish to move your pawn, through keyboard input, you will have to send the information to server, which will move the pawn, and replicate/broadcast new position.
Ok with this very few basics...
First, I will show you how to manage increase/decrease speed on my spaceship.
First I create new input in project settings
Next in my pawn Blueprint, I create two variables, speed, and speedmax.
Speed will be replicated. It is an information needed by client to manage UI and FX for example.
Replication is always from server to client.
I ve created next a new custom event in my blueprint. The event receives the new speed, and set the variable with it.
Event must be run on server
Finally, I receive my speed input (through A or W keyboard input), and I manage the increase of speed, and send it to server.
Pay Attention on switch authority. Switch authority allows to run what is after on server, or client. Here, because it is a client input, I have to manage following on client. So I choose remote.
If it was an event about collision for example, I must switch on authority, to manage it only on server.
If you don't use this switch, it will be run on both (client and server), and you can have strange behavior or maybe error. For example, if you manage to update an UI, on dedicated server, you will have errors, because there is no window for server.
Here, you will manage keyboard input to increase speed, and send the update to server.
Server will update speed variable, and because of that, the update will be replicated to all client.
To do better, you can send the input to server, which will manage the different test case, to be sure and guarantee no cheat :D
Inscription à :
Articles (Atom)