City Car Driving 2.0 – Developer Diaries #5

In the fifth diary we will tell you how we create game mechanics. In the first diary you have already seen part of them.

Most of the mechanic is written using a visual programming system Blueprint engine Unreal Engine.

How the automobile gas station works

The player arrives at the gas station, drives up to the hearing column, depending on the type of fuel and side of the fuel tank hatch, the event is triggered Overlap.

  • Event OncomponentBeginoverlap It is called when the player hit the trigger of the gas station, further logic is launched.
  • Macro Cartagsrefuel receives data from the car, what is the type of fuel, and on which side it has a fuel tank hatch.
  • Macro Datarefuelcolumn receives data from macros Cartagsrefuel, and compares them with the specified parameters of the gas station.
  • Function SENDINGDAGASSTATION forms and sends all data to the logic of refueling.
  • After the formation of the data, the refueling script is initialized.

The initialization of the script has been completed and the script signed up for the event Refuelstatus Through the node BindEvent to refuelstatus.

Now that this event will cause any other place, the event in our script will work. It is called Event Dispatcher.

  • As soon as the event to which the script is signed worked, post-event is called Refuel And the check chain is launched.
  • First, checking the state of the variable Refuelbuttonhovered (Pressed button or not) through the node Branch. This Node checks, whether the verified value satisfies with any specified conditions, in this case, a check for whether the value of the variable is the value Refuelbuttonhovered Truth or lies. If the button is pressed, the check is successful, t.To. the variable returns the value of True (truth), and the chain continues.

Checking through macro Checkstatuscar, inside which the following is checked:

  • The first two nodes Branch Check if the engine is drowned out and whether the parking brake is installed. If the check passes, Macro misses the course of the script further.
  • If the conditions are not fulfilled, then Macro simply waits for the performance of actions through Delay (Node of a temporary delay).

Next is checking and performing actions through macro Tankfilling, inside which the following is checked:

  • A variable confirmation of the refueling is initialized and is set to the value False (LIE). At this stage, our script is already ready for the end of the gas station.
  • After, the current fuel level is recorded in the variable Backupfuellevel and stored there until the end of the gas station.
  • In the variable Fuellevelconverted Previously, the level of completeness of the tank was formed in the decimal structure, t.e. The level of the tank is measured not in liters, but in shares from 0 to 1. After that through the Noda Branch It is checked whether the tank is filled to 1 whole.
  • Next is the script through the node Branch again checks whether the refueling button is still pressed.

After previous checks, a number of executive blocks are launched, in which clean mathematical operations occur with an interval of calculations equal to 0.1 seconds.

  • Block AddlitreinProgressbar Anims the level of filling of the tank inside the button "Refueling". The current value of the tank is summed up with fuel supply force.
  • Block Displayfuellitre sends to the user interface the number of refueling.
  • Block Addfuelincar adds fuel to the car of the car. Every 0.1 seconds are sent to the value of the tank level by 0.1 liter of fuel.
  • Block Filledfuel calculates how much the player flooded the fuel into the tank. The value of the previously given variable is taken from the current fullness of the tank Backupfuellevel.
  • Block Sumlitre forms and distributes data on refueling, sends data to the logic of refueling and to the logic of the car.

As soon as the player releases the refueling button, he has the opportunity to complete the refueling process and confirm the amount of refueling. When the completion button is pressed, the logic of confirmation is performed.

  • In the previously specified variable Backupfuellevel a new value of the tank level is recorded.
  • The user interface is closed.
  • A user message about a successful refueling is issued.

How the maintenance station works

Когда игрок заезжает в зону СТО, инициализируется скрипт логики СТО.

  • Function SetClasswidgetrepairStation creates a link to a class interface class inside a hundred.
  • Function Setclasswidgetrepairstationstatus creates a link to the class of car status.
  • The script is subscribed to the event Repairnded To get the player’s exit event from a hundred.

The player drove into a repair box, the logic of collecting and forming data for use in further chains of logic is launched.

  • Function Sizemodewidget triggers the mode of full access to the functions of one hundred. Then we display the mouse cursor on the screen, the variable is responsible for this Showmousecursor

Challenge of the event Adddetailist launches a logic chain that forms and sorts the parts of the car in the user interface

  • Through the design Foreachloop There is a redemption of all values ​​from the array Partslist. This is an array that contains a list of all car parts.
  • Further, each part is divided into separate values, which in turn are sent along the paths they need to the corresponding variable.
  • Function Createwidget creates an interface element into which the previously obtained values ​​from the list of parts are transmitted.
  • Inside the function SorterDetailist The resulting parts are sorted according to various functional blocks: "Body", "Chassis", "Electrician", "Engine".
  • Function Sortressourcedetail sorts a list of parts by the degree of their wear.
  • For further calculations for each specific part, the variable VehiclePart writes out data on the name of the part, the degree of wear and duration of the repair.

Challenge of the event Adddetailimage forms a block of visual display of the status of a car.

  • Through the design Foreachloop Again there is an overkill of all values ​​from the array Partslist.
  • Further from the data on the part, we get its image through the design Break Structure_partdetail.
  • Through the function Addchild a new place is added in the user interface unit, to which the image is sent.
  • We get a variable Detailimagebrush From the created place in the interface unit, to which we send the previously obtained image.
  • Function Setcolordetail sets the color of the sent image, depending on its wear.

Challenge of the event Activatemodeui activates the regime of interaction with one hundred.

  • Function Setinputmodeuionly sets a condition under which the player can only interact with the user interface.
  • Function StopmovementimMedialy stops the physical simulation of the player’s car.
  • Function SetViewtargetwithblend Changes the observation camera for the player. The current camera turns off and switches to the Camera STO.

In the event Senddatarepair The function is caused SendingDatarepair, which sends data about the player, car and details to the user interface.

At the current stage, the player can fully interact with the service station, see the status of the car, check the integrity of the parts, fix each part separately, choose several details for repair or immediately in one click to fix all the worn parts.

  • Event Buttonrepairpressed_event It works if the player has clamped the selection button of a particular part. In turn, this event causes the logic of the repair of one part. The selected part is checked inside the logic and is repaired, the value of wear is reset.
  • Event PartSelded_event works if the player has put on a specific part once. The selected part will be recorded in a check sheet for subsequent repair.
  • Event Buttonrepairedetails_event works if the player has put on the button "Repair the selected details". This event checks what details were chosen by the player when the event was triggered PartSelded_event and performs a function similar to the repair functions of one part.
  • Event Repairfulldetails_event works if the player has put on the button "Fix all the details". The logic will check all the details and find those whose resource is below 90%. Further, all these parts are sent to the repair function.

After the repair is completed, the player can leave a hundred. In this case, the script will perform a number of final logic:

  • Close the MOST mode. The player can no longer interact with the user interface.
  • Clean temporary variables.
  • Clean the lists of parts and details about the details.

How the car wash works

The system initialization system on the car wash is identical to other interactive objects. As soon as the player drives up to the sink and presses the interaction confirmation button – the gates open and the signal lamps light up and light up. At this stage, the washing awaits the car in the washing box.

We have implemented a system for tracing rays in a car wash instead of animations prepared for each car. This allows you to unify the logic of work, regardless of the type and shape of the car. In fact, with this implementation, logic works correctly with absolutely any object that enters the washing box. Invisible rays monitor the shape of the body and control the movement of all mechanisms.

  • calculates the length of the beam, which will track the shape of the body, and also checks the radius of the brush so that the geometry of the brush does not intersect with the geometry of the car.MacrosestimationVectortrace
  • "Shoots" a beam to track the point of its intersection with the geometry of the car body, after which it sends the coordinates in which the intersection occurred, then.Function bylineTracebyChannel
  • receives the obtained coordinates of the intersection and moves the brush to this point.Function

Ray tracing is used in the logic of all movable mechanisms of the washing complex:

  • Washing brushes
  • Washing machine
  • Washing in nozzles

Also, on the car wash there is an opportunity to skip the process of car washing, for this we added the opportunity to drink coffee.

  • works when the player clicks on the button "To drink coffee".Event Clickedbuttoncoffee_event
  • will fulfill logic once, without the ability to press the button repeatedly during the current session of the sink.Operatordoonce
  • calculates the possibility of using sipping.Macroscalculatecoffee
  • , the implementation of which triggers the process of missing the washing. The screen is darkened, the brushes return to the starting position, the washing box is turned off. Having received approval from the macros, the event phorcended is called

After the car washing is completed, the degree of body pollution is discarded, the gate is opened. The player can now continue the game by leaving the washing box.

How the garage works

The garage is the only place where, when entering the zone, the player must fulfill the full stop of transport, namely:

  • put the car on a hand brake;
  • turn off the headlights;
  • drown out the engine;
  • to unfasten.

This is realized as follows:

  • receives a link to the car, and also checks its initial state. When entering the garage, the player has a widget with a list of necessary actions.Blueprint
  • When the condition changes, it transfers through the interface what parameter it has changed and what.
  • After that, a new state of the car is noted in the widget and it is checked whether the player fulfilled all the conditions.
  • And if all conditions are fulfilled, the main logic of the garage is launched.

Here the player’s car is added to an array of garage machines (under the zero index), and the player himself gets the opportunity to use the functionality of the garage.

Bed – allows you to rewind time, causing a function in a separate class that controls the time at the level.

  • Addtime – Function in the classroom LEVELTIME, the increase in time to the current state, which the player indicated in the widget.

In the next issue, we will not talk much and prepare for you a set of screenshots of the project for the entire development of it.

Development diaries come out every two weeks. Do not miss!