Introduction

In this article we are going to see how to make sections and cut objects in Blender as seen in figures 1 and 2. For this we are going to use the tools “Knife” and “Bisect”.

cut object in blender with the bisect tool
Fig. 1: Bisection of the cube.

Fig. 2: Cut on one side to form a crack



If you prefer to watch a video I have the right video for this topic:


Procedure to Cut Objects in Blender

The tools we are going to use are Knife and Bisect, we can see them in figure 2. The knife can be accessed quickly with the K key.

Fig. 3: These are the tools for cutting or sectioning objects in Blender.

Fig. 4: All the faces that are going to participate in the cut must be selected.

Bisect Tool

Let’s start by using the bisecting tool that will allow us to cut an object in two parts.

To use this tool, all the faces that will be involved in cutting must be selected. Then we mark two points on the object (figure 5), this will draw a plane perpendicular to the view and that passes through these two points, on this plane we will make the cut of the object. In figure 6 we can see the result.

Fig. 5: With the Bisect tool two points must be marked to make the cut.

Fig. 6: The cube was divided into two parts.

Taking the result of figure 6 we can remove the top and create a new face, getting the result we were looking for.

You can also separate the object into two parts, here you can see how.

Fig. 7: We can remove the top and create a new face selecting the vertices and pressing F.



Knife Tool

Now let’s look at the knife tool, the shortcut is the letter K.

With the knife we can obtain a similar result as with the bisect tool, we mark the points where the cut will be made and at the end we press Enter.

Fig. 8: With the knife tool we can achieve a similar result.

Fig. 9: We mark the vertices of the cut and press Enter at the end.

Fig. 10: New faces have been created as a result of cutting.

The knife tool allows us to make irregular cuts in any part of the object, in this case we are going to make a crack on one of the faces making a star-shaped cut.

If we double-click while making the cut, the end point will automatically join the starting point.

Fig. 11: With the knife tool you can make irregular cuts in any part of the object.

To create the crack we select the new star shaped face, press E to extrude, S to scale and make that new face smaller and the G key followed by X to move the face in the X axis direction.

Fig. 12: At the end of the cut we have a new face that we can manipulate.



Introduction

In this article we are going to see how to create a simple 3D text in Blender from any font of your choice either from the Fonts folder of the system or any downloaded font from the internet. The procedure consists of creating a Text object that is a resource that Blender has to generate texts and configure different parameters such as alignment, font size and others. With this we obtain an editable text, from there we can convert that object into a Mesh, that is to say a 3D model with vertices, edges and faces.

In the following video I explain how to CREATE a SIMPLE and fast 3D TEXT in Blender


Summary: How to create simple 3D text in Blender

1. Get the font file to be used. It can be a font from the Windows > Fonts folder, or a downloaded font, from pages like 1001Fonts or DaFont for example.

2. In Blender, while in object mode, press SHIFT+A and add a “Text” object.

3. With the text object selected, enter the edit mode with the TAB key and write the text.

4. In the properties window (the window where you select the rendering engine or create materials), go to the “Text tab, which has an icon with the letter “a”, there you can select the font in the “Font” section and modify other text properties such as alignment.

5. In the same “Text” tab go to the “Geometry” section and increase the “Extrude” parameter, with this we will be able to modify the volume of the text.

6. When we finish editing the text we return to object mode, right click on the text and choose the option “Convert To Mesh“. This will turn the “text” object into a 3D model with vertices, edges and faces that we can edit.

Detailed procedure for making 3D text in Blender

In my case I’m going to download a font from the “1001 Fonts” page. If the font you like is already installed on your system, you can find it in the path “Windows/Fonts/”. Make sure you know the location so you can locate it in Blender.

Fig. 1: We chose a font for the 3D text.

In object mode, press SHIFT + A and add a new text, as shown in figure 2. Then, with the text selected, press Tab to enter edit mode and write the text you want.

Fig. 2: We add a text object.

Fig. 3: With Tab we enter the editing mode and write the text.

When we have a Text selected a tab appears where we can configure all the properties, we can see it in figure 4. Inside that tab we go to the Fonts section and click on the button to open (figure 5).

Fig. 4: Let’s go to the text tab that appears when we have a text object selected.

Fig. 5: In the Font section we click on the button to open the font.



Using the explorer we look for the font we have chosen.

Fig. 6: We select the font in the explorer.

I’m going to center the text on “Paragraph – Alignment” (figure 7) and to make the letters 3D we go to the “Geometry” section and give a non-zero value to “Extrude”.

Fig. 7: We can align the text.

Fig. 8: To give volume to the text we go to “Geometry” and increase the value “Extrude”.

This makes the text now have depth, as we see in figure 9.

Fig. 9: We set all the necessary parameters until we obtain the desired result.



Convert Text Object to Mesh in Blender

When we finish editing the text we return to the object mode, right-click on the text and choose “Convert To Mesh”, this will make the text object become a 3D model.

In figure 11 we see the geometry of the 3D letters.

Fig. 10: We convert the text object to Mesh, that way the letters will become a 3D object.

Fig. 11: When entering the editing mode we can see the geometry of the 3D letters.



Introduction

In this article we see how to make holes in Blender using the “Boolean” modifier in the “difference” mode, this allows us to remove the volume that occupies a second piece inside the object. You will also find a video showing how to use the boolean modifier in video.

There is a video tutorial on this topic:




Procedure for making holes in Blender

We are going to take a cube and make a hole in it using a cylinder, as shown in figure 1.

Fig. 1: We start with a cube and a cylinder.

Select the cube and go to the “Modifiers” tab, shown in figure 2. Then add the Boolean modifier, as shown in figure 3.

Fig. 2: Select the cube and go to the modifiers tab.

Fig. 3: We added a Boolean type modifier

In the “Object” field of the modifier we have to assign the object that is going to make the cut, in our case the cylinder. We can use the eye dropper to select the cylinder or we can choose it from the list.

The operating mode must be “Difference”, so that all the space occupied by the cylinder inside the cube is eliminated, as shown in figure 4.

Fig. 4: In the Object field, we select the cutting object, in this case the cylinder.

Then we place the cylinder where we want the hole to be made.

Fig. 5: We position the cylinder according to how we want the hole.

If we go to the Outliner and hide the cylinder (figure 6) we see that the piece has already made the hole.

Fig. 6: We hid the cylinder in the Blender Outliner to see the result.

Fig. 7: Hiding the cylinder shows that a hole has been made in the workpiece.

When we don’t have to make any more changes, we can apply the modifier to make the cut effective. In figure 9 we see how the geometry looks after applying the modifier.

Fig. 8: We apply the Boolean modifier to make the cut effective.

Fig. 9: En la geometría podemos ver el corte.


You have reach the end of the article, if it was useful consider subscribing to the channel!

Introduction

This download for Unity consists of a 3D model of an antique style wall clock, Roman numerals and a wooden frame. The hands are functional.

The download includes the PBR textures with 512 x 512 resolution.

In the following video you can see how to import packages in Unity.

Download Unity Package

Content of the Package

Inside there is a 3D model of the clock, three textures (Albedo, Metallic and Normal). Two scripts to set the clock and test that functionality. A scene in which everything is configured, when you open this scene and enter the game mode, the clock model will show randomly different times.

How to use the Wall Clock for Unity

The Clock is controlled using the “GDTClock” script, this has a public function called “SetTime” that allows to set the time.

In simple terms, to use the clock we must create a Script that controls it, inside this Script we must define a reference of the class “GDTClock” and find the reference of this object in the hierarchy, this last one we can do manually defining the object “GDTClock” as public or serialized and then dragging the GameObject of the Clock to the field in the inspector. The “WallClockTest” script inside the package shows how to use the clock.

I leave you an article about Communication Between Scripts in Unity. With this you can understand in detail how to use this clock.

Introduction

In this article we see the instructions we need execute in order to quit the game in Unity, then we will make a button call the exit function when pressed.

In the following video you can see the complete process in which we see how to close the game in Unity, from the creation of a simple Canvas to test the function, to the script with the necessary functions.


User Interface for Testing

We are going to use a very simple user interface that will consist of a button that when pressed will execute the function to close the game.

Script with the Function to Quit the Game

We will create a script called “Control” that will be assigned to any GameObject in the hierarchy and will contain a public function called “Exit” (see what is a method in programming and how to use it).

Within the “Exit” method we will place a single instruction that will be in charge of closing the game.

Application.Quit();

The idea is that the button on the user interface will execute this function when it is pressed.

For this we select the button in the hierarchy and in the inspector, in the OnClick section we click on the little plus sign to add a new field, we drag the GameObject that has the public function to close the game and using the drop-down menu we look for this function in the list.

Conclusion

We’ve seen very simply how to close the game at Unity. For this we must execute the “Application.Quit()” instruction somewhere in the code. In this case we execute it when we press the exit button of the user interface, but we could do it in different ways.

Now it is time to think about what tasks we should carry out when closing the game and make sure they are executed before the Quit instruction. For example, what information should we save to retrieve in the next session?

EXTRA: Quit application with confirmation dialog

🎁 UNITY PACKAGE: Exit application with confirmation dialog

ABOUT THIS SOLUTION

  • By clicking in Download you will get a file with “Unity Package” extension. Drag and drop that file into Unity to import it.
  • When you import this Unity Package you will find a folder with a scene, a script and some extras.
  • Open the scene and you’ll find detailed information about how this solutions works.

🟢 How to quit application with confirmation dialog

Introduction

In this article we see how to join and separate objects in Blender. We start by understanding what an object is in Blender, then we start with two separated objects and join them together to form a single object. Finally we take this object composed of two parts and we are going to separate it again into two different Blender objects.

What is an OBJECT and what is a MESH in Blender?

Blender has different working modes, when we are modeling in 3D two of the most used modes are “object mode” and “edit mode“, in object mode we work with the objects in the scene while in edit mode we work with the geometry that a specific object or a set of objects has defined inside them. Objects are entities that have at least one reference point called origin and have an associated transformation, that transformation consists of information about its position in space, its rotation and its scale. An object in Blender can be empty and simply serve to mark a coordinate in space, but normally if we are modeling in 3D the object will have defined a Mesh, which is a set of vertices, edges and faces that are connected in a certain way, the object could also contain several meshes not connected to each other.

Now that we have seen a more precise idea of what are objects and meshes in Blender let’s see how is the process to join and separate objects in Blender.

In the following video we see the process to JOIN and SEPARATE OBJECTS in Blender


How to join objects in Blender

We start from two separated objects as seen in figure 1, in the Outliner of figure 2 we see that they are two separate objects.

Fig. 1: We start with two separate objects.

Fig. 2: In Blender’s Outliner we can see that these are two different objects.

We select both objects using SHIFT and right click to display the menu shown in figure 3. We choose the option “Join” to combine both objects into one.

It is convenient to learn the shortcut CTRL+J to save time.

Fig. 3: Select both objects, right click and use the “Join” option.

In the Outliner we see that we now have a single object composed of both cubes.

Fig. 4: In the Outliner we see that the objects have come together and are now one.

How to separate objects in Blender

Now we want to reverse the process, we start from a single object composed of several parts and we would like to take one of those parts and separate it into a new object.

To do this we enter the edit mode (TAB shortcut) and select all the vertices we want to separate into a new object. In the video I select a vertex of the cube and then I use the shortcut CTRL+L that allows me to select all the vertices that are connected.

Fig. 5: To separate the objects in Blender, we select all the vertices we want to separate.

Then we right click to display the menu shown in figure 6 and go to “Separate”. We can also use the shortcut with the letter “P” to display this menu.

We choose the “Selection” option to separate all the selected vertices into a new object.

Fig. 6: Right click and go to the “Split” option. You can also use the menu shortcut to separate objects with the letter “P”.

Fig. 7: We choose the option “Selection” to separate the selected vertices into a new object.

In figure 8 we see that we now have two different objects in the Outliner.

Fig. 8: In the Outliner we see that the objects have been separated and now there are two.

Introduction

In this article we will see a downloadable solution that consists of a conveyor belt made in Unity, whose operation is controlled using an Arduino plate.

Downloads

In the next package you will find two folders, one with the Unity files and one with the Arduino files.

Inside the Unity folder you will find a compilation to test the simulation and also a Unity package that you can import into your project and access the assets of this simulation.

Upload the program to the Arduino

In the downloads you will find a folder called “Arduino”, which contains the program that reads the digital entries, forms a word and sends it through the serial port.

The program is quite simple so it will work on any Arduino board you can get, in my case I used an Arduino Mega.

In the following video you can see how to record the program on the Arduino board, you will need the Arduino software.

https://gamedevtraum.com/wp-content/uploads/en/game-development/unity-tutorials-and-solutions/conveyor-belt-in-unity-controlled-by-arduino/conveyor-belt-in-unity-upload-arduino-program.mp4
Video 1: Upload the program in Arduino

Circuit for digital inputs

The Arduino program that comes with the download uses pins 2 and 3 for the digital inputs. Pin 2 controls the status of the feeding machine and pin 3 controls the status of the conveyor belt.

There are many ways to connect signals to the Arduino’s digital input, I will show two alternatives using switches.

WARNING
BE SURE TO CONNECT THE ELEMENTS TO THE ARDUINO PROPERLY, A SHORT CIRCUIT CAN DESTROY THE BOARD.
IT IS NECESSARY TO KNOW THE LEG DISTRIBUTION OF EACH PARTICULAR CONTACT, BETTER IF YOU HAVE A TESTER TO MEASURE CONTINUITY.

Alternative 1: Two-position switch

In my case I used two position switches for the digital inputs, in these switches the middle terminal makes contact with one end or the other depending on the position of the switch. Therefore, at the ends we connect the high and low voltage signals (in my case 5 Volts and 0 Volts respectively). The middle terminal of the switch is connected to the digital input of the Arduino.

I repeat the warning, the switch I used is like the one shown in figure 1 and in this particular case it is connected that way.

Fig. 1: Wiring diagram of a two-position switch for digital input of the Arduino

Alternative 2: Pull-up resistor switch

Perhaps you only have one switch, i.e. a contact that closes or opens. In the Arduino’s digital inputs there should be constant high or low voltage signals, we should not leave digital inputs unconnected to anything (connection to the air as we say here) as this will lead to unpredictable behavior.

To do this, a small circuit with a pull-up resistor must be implemented, as shown in figure 2.

In this case we use a resistor connected to the GND terminal of the Arduino and the other end connected on one side to the digital input and on the other to the switch, the other end of the switch is connected to the high voltage signal (5 Volt for example).

Fig. 2: Wiring diagram of a pull-up resistor switch for digital input of the Arduino.

The circuit in figure 2 works as follows: when the switch is open there is no current flowing through the resistor, therefore the 0 Volts are transferred to the digital input and the Arduino reads a low level. When we activate the switch the current will flow through the resistance and the Arduino’s input will have a high level signal.

Check if the Arduino program is working

The Arduino program is in charge of reading the status of the digital inputs, creating a binary word that represents those states and sending it by serial port.

If we open the Serial monitor, from the Tools tab, we should see the states of the digital message inputs. As you can see in the following video.

https://gamedevtraum.com/wp-content/uploads/en/game-development/unity-tutorials-and-solutions/conveyor-belt-in-unity-controlled-by-arduino/conveyor-belt-in-unity-test-serial-port.mp4
Video 2: Check that the Arduino program is working

Test the simulation

Once we have recorded the program on the Arduino board, we can run the compilation that comes with the download.

When entering the simulation, in the upper left corner there is a button to connect Unity to the Arduino board.

In this part you may have problems with the connection, probably correct this in another version of the solution. To make sure the connection works, the Arduino board must be connected before opening the compilation and the connection process may take several seconds to complete. If after 30 seconds the board is not connected, check the previous step and reopen the simulation and try again.

Video 3: Prueba de la cinta transportadora en Unity controlada por Arduino.

Import package and fix “API Compatibility Level” error

To access the source files of the simulation is the Unity package, you can import it as seen in the following video.

Video 4: Import bundle and fix API Compatibility Level error

When importing the package we will get errors because some scripts cannot access the package with the classes that allow access to the serial port.

To fix this, follow the steps shown in video 4. Go to Edit > Project Settings > Player > Other Settings and in the field “API Compatibility Level” set “.NET 4.x”.

How the Conveyor belt in Unity controlled by Arduino works

Inside the package is the scene that is seen in the simulation, we can access it and see its elements, in figure 3 we can see the hierarchy of the scene.

In the hierarchy we have three machines, “Toori Machine” is the machine that places objects on the conveyor belt. “GDT Conveyor Belt” is the conveyor belt and “Box” is the box where the objects fall and are destroyed.

Fig. 3: Hierarchy of the scene that comes inside the package.

Conveyor Belt

The conveyor belt is a 3D model with a structure and a belt.

To achieve the animation of the operation what is done is to add offset to the UV map of the texture. In this case, as the texture is vertically distributed, we add offset to the Y component of the UV map. When the UV map has an offset of 1 in the Y component the texture returns to the initial state.

So to achieve the effect of the conveyor belt moving forward or backward we gradually increase the UV map offset on one of the components.

To make the belt transport objects, you have a Collider box in Trigger mode that detects when an object is on the belt, these objects must have a RigidBody component assigned to them.

Fig. 4: Script that controls the conveyor belt in Unity

Then in the Conveyor Script you define the OnTriggerStay function that will be called when an object is on the conveyor belt. This function will be in charge of moving the object, to synchronize the movement of the belt with the movement of the object there is a parameter in the inspector called “SyncUVMovementFactor”, by default it is set to 2, as shown in figure 2.

The conveyor belt has a public function that allows it to be activated or deactivated and that can be called from any other Script. We execute this function with the information we read from the Arduino board, that is, it will be activated or deactivated according to the status of the digital input 3 of the board.

Feeding Machine

To make the simulation a little more complete, a machine that places objects on the conveyor belt is included. This machine is controlled with the “FeedingMachine” script and also has a public method that allows you to turn it on or off. This machine will be controlled with the digital input 2 of the Arduino.

Fig. 5: Script that controls the machine that places objects on the conveyor belt

In the inspector we can place the prefab of the objects to be placed on the conveyor belt and we can change the times between one object and another.

Communication between Arduino and Unity

Esta parte se resuelve utilizando una versión modificada de la solución WRMHL compartida por el equipo RELATIVTY. Te animo a visitar los links para ver la solución original y los proyectos.

This part is solved using a modified version of the WRMHL solution shared by the RELATIVTY team. I encourage you to visit the links, see the original solution and the projects they have.

In order to communicate Unity with Arduino you must have a GameObject in the hierarchy with the “wrmhlRead” script assigned.

Fig. 6: Script that controls communication between Arduino and Unity

I have added an integer called “arduinoMessageLength” in the inspector, which indicates the length of the binary word that is sent from the Arduino. This is used to correctly synchronize Unity with Arduino in case there are more devices using the serial port.

In our case, since we sent a two-digit word from the Arduino, you must put two in that field. If you add more digits to the word, you must modify this field appropriately.

The reading of the Arduino message is done in the “ReadMessageAndAction()” method. Here inside we can perform the action we want in Unity. In our case we execute the public methods of the ConveyorBelt and FeedingMachine scripts, to activate or deactivate the machines according to the Arduino’s command.

Conclusion

We’ve seen how the conveyor belt solution works at Unity controlled by Arduino.

With the files provided you can create a new simulation according to your needs.

Introduction

In this article we see what MODULARIZATION is in programming and why it is important. We will also see examples of applications in C# language in Unity.

What is MODULARIZATION in Programming and what is it for?

The word modularization comes from module, whose textual definition is: ” each of a set of standardized parts or independent units that can be used to construct a more complex structure, such as an item of furniture or a building”.

Modularization is the process by which we select and group programming instructions that fulfill a specific function.

Creating modules is important because of the following:

Suppose we have a problem, as complex as you want, and the solution is to execute as many programming instructions as you need. Using programming modules, we can build a solution that can be executed using only one instruction. This instruction will go to the content of the module, execute each of its instructions and when the program ends, it will return to the point where the module was called.

The advantage of this is that we create the module only once and then we can reuse it as many times as necessary and from any part of the code, in addition, we no longer need to think about the internal functioning of the module, we use it as a whole that we know will perform a certain function. In other words, we increase the degree of abstraction of our code.

Fig. 1: On the left is a list of instructions with repeated code. With a module we can reuse the code and get something more compact as seen on the right.



Characteristics of the modules in programming

Regarding Functionality

A module should have a specific function and not go beyond its responsibilities. For example, if we have a module that calculates the product of two numbers and returns the result, it would not be appropriate for it to also print messages on the screen or do anything else that goes beyond its purpose.

Regarding Identification

The modules have an identification name that allows us to execute them, it is recommended that we choose this name so that it is as representative as possible of the function it performs, that way it is more intuitive when using it.

Input parameters

The modules can accept input data that will be used by your internal instructions to perform the function.

When defining a module, you should indicate all the parameters it requires and what kind of data it is. At the moment of executing the module, all the necessary parameters should be added, in the established order and they should be of the right type.

Output parameter

The modules can return a data as a result of its execution.

When defining a method, the type of data it returns must be indicated and the last instruction of the module must be the return of that data. When the module is executed, it must be taken into account that the call to that method implies a data as a result, so we must see what is done with that data, we can, for example, assign it to a variable or an object.

Visibility

When we define a module we can give it different types of visibility that will limit the access to them, for example the modules that belong to the internal functioning of a programming class are usually defined as private, so they cannot be accessed from a context external to that class.

In C# we have three types of visibility, public, private and protected.

Public visibility implies that the function can be accessed from any context, i.e. we can for example execute the function from another programming script.

Private visibility implies in simple terms that the module can only be accessed from the programming script itself.

Protected visibility is used when we have class inheritance and serves to allow subclasses to access these modules, but not external classes.

Fig. 2: This picture summarizes the main features of a programming module.



Definition of a programming module in C#

To create a module in C# we are going to use the declaration syntax of a programming method, which consists in first indicating the visibility type, then the return data type (or write “void” if it does not return data), then the module identification name (it is recommended to start with capital letters and use camel case), then between parentheses all the data required by the method including the data type and finally the keys are opened and closed. All the instructions of the module will be inside those keys.

In figure 3 we can see the syntax of several generic modules, all of them with public visibility (to make it private we must use the word “private”).

On the top left we have a module that does not return data (void is used in the definition) and neither requires input parameters (it opens and closes parenthesis).

At the top right we have a method that does not return data and requires a number N of parameters (we see that in brackets are included the data separated by comma). The parameter p1 could be for example “bool b1” indicating that it is a bool type and its name is “b1”. So, inside the module we can use b1 knowing that it is the information that comes from the outside.

Fig. 3: Generic examples of the syntax of the modules in programming

In figure 3, at the bottom left we have a method that doesn’t require input parameters but does return a data, since next to public it says “datoX”. Instead of datoX we have to put a data type, like a primitive variable or an object, for example “int” indicates that the module returns an integer value, while “Vector3” indicates that the module is going to return an object of the Vector3 class. Note that at the end of the method a value of name X is returned, this value must be of the same type that was declared in the method.

In figure 3, at the bottom right we have a method that requires parameters and returns a data.

Example of a module in C#: Calculating the area of a circle with a certain radius

We are going to design a module that is in charge of calculating the area of a circle. This module will receive as parameter a real value that represents the radius of the circle and will return a real value that will be the value of the area of a circle with that radius.

Pseudocode

Function AreaOfCircleWithRadius (FLOAT radius)
– BEGIN
– – Float area <- PI * radius * radius
– – RETURN area
– END

Implementation with C#

The syntax in C# language of a method based on the above pseudocode is as follows.

Module Definition

private float AreaOfCircleWithRadius(float radius){
      float area = Mathf.PI * radius * radius;
      return area;
}

Of course this is not the only option, you can also do:

private float AreaOfCircleWithRadius(float radius){
      return Mathf.PI * radius * radius;
}

Calling the module

Then we can for example make use of this programming module from Unity’s Start method in the following way:

void Start(){
      float r = 5;
      float a=AreaOfCircleWithRadius(r);
      Debug.Log("The area of a circle with radius: "+r+" is: "+a+".");
}

Introduction

In this article I present a solution to automatically create cables that hang from two or more points. The system allows us to modify the thickness of the cable, the curvature and more parameters to achieve the result we want.

The wire is drawn using Unity’s Line Renderer component so it is generated procedurally using mathematical expressions.

Unity Package

The solution consists of a Unity package that you can import into your project, this will create a new folder in your project with the Assets that come in the package.

How the Wiring System Works

Figure 1 shows the Assets that come in the package. In the scene you can see a power line that I generated using the wiring system.

To start using the system we can drag the prefabricated “GDT Wire Container” into the hierarchy (blue cube in figure 1). If you can’t create a new Empty GameObject and assign it the “GDTWiringSystem” script this will automatically generate everything needed for the system to work.

Fig. 1: The download package contains these assets.

The object assigned to the “GDTWiringSystem” script will be the one to draw the cable and its children will be the points from which the cable will be hung.

In figure 2 we see the “GDTWiringSystem” component, here is all that is needed to shape the wiring.

Fig. 2: In the inspector we can modify the wiring parameters.

Adding new points for the cable

To create a new holding point for the cable, simply right click on the container object and then click on Create Empty, as shown in Figure 3. This will create a new child and the script will automatically name it.

I do not recommend creating new children by duplicating existing ones, as this produces internal errors.

Fig. 3: To add a new point to the wiring you have to create a new child in the GameObject container.

Fig. 4: A new holding point is created for the cable.

In figure 4 we see how when creating a new point, a new section of cable appears.

Wire loops

If we want to generate a cable with its ends connected we can activate the option “loopWire”, this will generate a new stretch of cable that joins the last point with the first one.

Fig. 5: The loopWire option makes the last point of the cable connect to the first point.

In figure 6 we see that the cable has been closed.

Fig. 6: With the loopWire option we see that the cable forms a closed curve.

Wire Smoothness

The subdivision parameter allows us to choose the amount of segments that will be between two points of the cable, initially it is 1, which implies that the points of the cable are joined with straight lines, for the cable to have curvature we must choose a subdivision parameter greater than 1.

The larger the subdivisions, the smoother the cable curvature. The maximum range is set to 15 but it can be increased by opening the script and modifying the “[Range(1,15)]” instruction with the required value.

Fig. 7: If we increase the subdivisions we will get smoother curves.

Cable Curvature

To modify the concavity of the cable, that is to say how intense its curvature is, we have the Sliders inside the “Curvature Parameters” vector, as we see in figure 8.

The default range of these sliders is -3 to 3, but if necessary you can modify it from the script in the “[Range(-3f,3f)]” instruction by typing the required value.

Fig. 8: The bending parameters allow us to adjust the concavity of each cable section.

Animation

In case you need to animate the cable, I added a bool called “isAnimatedWire”, when you activate it the cable will be drawn in each FixedUpdate execution that by default is executed every 20 mili seconds.

Result

Using this solution we can automatically draw cables suspended from two or more points. We can add as many points as we want and modify the curvature of each section individually.

The cable is drawn with the LineRenderer component and using mathematical expressions.

Fig. 9: As the subdivisions are increased, the curvature of the cable can be seen.

Introduction

In this article we will see different ways to calculate the distance between two objects in Unity, this can be useful for example to know how far is the character from a certain point of the scenario or to activate mechanisms when the character is at a certain distance.

All the IMPORTANT information is summarized in the following TUTORIAL FROM MY YOUTUBE CHANNEL




Setting up the scene

Let’s make a very simple scene that will have two spheres with 3D texts to indicate the number of the sphere and the distance between them.

Fig. 1: These are the GameObjects in the scene hierarchy.

Fig. 2: Script that will take care of the calculations.

The camera will have assigned the Script named “Distances” which is the one that will calculate the distance and write the values on the screen. As an extra, we’ll add a Line Renderer component to draw a line from one object to another.

In figure 2, we see that there are fields for both objects and for the distance indicator. We also have an enum that allows us to choose if we want to calculate the distance in space or projected in a certain plain.

Fig. 3: This is how the scene looks with the objects.

Preparing the Script

The Script that solves the calculations calls “Distances” (complete Script at the end of the article), in the following figure, we can see the fields defined in this Script and the Start method.

Fig. 4: Fields and Script Start method for calculating the distance between two GameObjects.

We have serialized fields (appear in the inspector) to assign the two spheres from the hierarchy, a TextMesh component for the distance indicator and the enum that allows us to choose which distance we want to measure.

Fig. 5: Code of the Update method.

In the Start method, we find the reference of the Line Renderer assigned to the GameObject camera.

In the Update method, we are going to do the calculations, for this, we define two methods “CalculateDistanceInSpace” and “CalculateDistanceXYPlane”, this last one takes into account only the X and Y components of the objects as if the objects were projected in the XY plane, this is useful when we use the orthographic view. In figure 6 we can see these methods.

Article about “Methods” in programming

Fig. 6: Methods for calculating distances in space and in the plane.



Calculate distance between two objects in space – Vector3

Let’s start by looking at how to calculate the distance between two objects in space, i.e. considering the three dimensions of the scene.

The CalculateDistanceInSpace method in Figure 6 takes care of this. As you can see, the “Distance” function of the Vector3 class is used and we use the positions of the objects as parameters, this method will return the distance between the two vectors.

https://gamedevtraum.com/wp-content/uploads/es/desarrollo-de-videojuegos/tutoriales-y-soluciones-para-el-motor-unity/calcular-distancia-entre-dos-objetos/distancia-entre-dos-objetos-espacio-unity.mp4
Video 1: Distance between two objects in space.

Calculate distance between two objects in the plane – Vector2

If we are working in 2D or if we are interested in knowing the distance between two objects projected on a plane, we can calculate this distance using only two dimensions of the scene.

The CalculateDistanceInXYPlane method in Figure 6 takes care of this. As you can see, the Distance method of the Vector2 class is used, two vectors are built using only the x and y components of the position of the objects and they are passed as parameters to the Distance method of Vector2.

https://gamedevtraum.com/wp-content/uploads/es/desarrollo-de-videojuegos/tutoriales-y-soluciones-para-el-motor-unity/calcular-distancia-entre-dos-objetos/distancia-entre-dos-objetos-plano-unity.mp4
Video 2: Distance between two objects in the plane.

In the following video, we can see the difference between these two ways of calculating distances between objects in Unity.

https://gamedevtraum.com/wp-content/uploads/es/desarrollo-de-videojuegos/tutoriales-y-soluciones-para-el-motor-unity/calcular-distancia-entre-dos-objetos/distancia-entre-dos-objetos-unity.mp4
Video 3: Comparison of the distance between two objects in the plane and in the space.

Conclusion

We have seen how to use the classes Vector3 and Vector2 to calculate distances between objects in space and in the plane respectively.

In general Unity works in 3D space, therefore to measure distances in two dimensions it is necessary to project the points in some plane. We have to take into account that there are several planes that we can use, in this case, we used the XY plane, but there is also the XZ, the YZ plane and we can even define a plane oriented in any direction.

Appendix

Here you can see the complete script that calculates the distance between two objects in Unity.

Fig. 7: Script Distances.

Introduction

In this article we will see how to define the factorial operation of a number, calculations and properties. It is a useful operation that is commonly applied in the development in series of functions.

Definition of the Factorial Function

This operation is symbolized with the admiration symbol in front of the number to apply it, the factorial of 3 is symbolized !3.

Applies to natural numbers including 0. This means that we cannot calculate the factorial of a negative number or a number with decimals, see numerical sets for more information.

The factorial of 0 is equal to 1, that is !0 = 1.

The factorial is equal to that number multiplied by the factorial of the previous number. We can continue applying this property until we reach the factorial of 0.

We can represent this operation using the product notation, in the following way:

(1)  

One way to calculate the factorial in programming is to use this producer notation and solve it in a loop, as we saw in the article about summation and product notation.

Examples of use of the factorial

Power Series Expansion

An example of the use of this operation is in the Taylor Series or power series expansion, which consists of a series of infinite terms to which we can adjust the coefficients to approximate a function that we want and that meets the minimum conditions for this to be possible.

Fig. 1: Desarrollo en Serie de Taylor de una función f(x). Aplicación del factorial.

Notice in figure 1 in the divisor of the summation term there is a number ranging from 0 to infinity and the factorial is applied to it.

The series approach is very useful because it allows us to find numerical solutions to certain problems, instead of evaluating a complicated function or even an unknown function, we evaluate polynomials.

Combination

The combination is useful for various applications, for example to find out how many possible combinations exist between certain quantities. You use factorials in the definition of combinatorial numbers:

   

Conclusion

We have seen the factorial operation that is symbolized with the exclamation point and is defined as a multiplication of a number by all the natural numbers before it.

The factorial applies to natural numbers including 0.

The factorial of 0 is equal to 1, henceforth, the factorial of a number is defined as the product of all natural numbers up to that number.

Introduction

In this article I share a mix of environmental instrumental rock that I prepared to listen to when I am writing articles or programming.

For this mix I have selected 16 songs from the YouTube library. The mood of the songs at times is calm, other times more moved, without becoming extreme, which allows me to isolate myself from the environment without distracting me.

Instrumental Rock Mix

Without further ado here you can listen to the instrumental rock mix, I hope you like it 😀

Names of the Songs and Artists by order of appearance

00:00 – 03:32 Without A Sound – Letter Box
03:32 – 06:15 Open Highway – Silent Partner
06:15 – 09:53 Lay It Down – Silent Partner
09:53 – 14:20 Don’t Look – Silent Partner
14:20 – 16:59 Silver – Riot
16:59 – 23:22 1973 – Bruno E.
23:22 – 26:05 Double You – The Mini Vandals
26:05 – 30:28 Town of 24 Bars – Unicorn Heads
30:28 – 34:34 Remembering Her Face – Silent Partner
34:34 – 38:04 Promises – Letter Box
38:04 – 41:03 In the Shadows – Ethan Meixsell
41:03 – 46:09 To the Sun and Back – TrackTribe
46:09 – 48:55 The Big Conference – DJ Williams
48:55 – 53:35 Heading West – Audionautix
53:35 – 57:45 We Could Reach – Freedom Trail Studio
57:45 Texas Napkin – Freedom Trail Studio

Introduction

In this article there are decorative 3D models to download and use in your projects at Unity.

For each model there are representative images and a brief description of the model, indicating data such as the topology and the quantity of materials.

The models are in .fbx format and can be imported directly into the Unity engine.

You can use these models to build prototypes quickly. I hope you find them useful.

Frames

This set of paintings is prepared for you to import it into Unity and you can put any image you want, as long as they are square or aspect ratio 16:9 or 9:16.

It also has several textures for the frames.

Vertices: 36 Faces:  27

Table

A simple table for 6 people with PBR textures.

Vertices: 184 Faces: 186

Chair

A simple chair with PBR textures.

Vertices: 132 Faces: 88

Shelf – 4 Shelves

Shelf model with 4 shelves. In the download are included the 3 textures that are observed in the image.

Vertices: 72 Faces: 55

Shelf – 3 Shelves and drawers

Shelf model with 3 shelves and a space for drawers or doors. This space is not functional, i.e. the drawers cannot be opened, it is only decorative. In the download come the two textures that are seen in the image.

Vertices: 68 Faces: 56

Chess Set

Set of chess pieces and table. Each piece is an individual model and can be given movement.

Vertices: 4169 Faces: 4102

Candlestick

Vertices: 256 Faces: 231

Introduction

In this article there are Seamless PBR Textures of floors to download and apply to your 3D models.

A Seamless texture is a texture with horizontal and vertical symmetry in such a way that it can be placed one after the other and the result is a continuous texture.

The term PBR is “physics-based rendering” and means that these textures are prepared to behave appropriately with light sources. These particular textures are adapted to the Unity engine (Metallic Workflow).

For each texture there are representative images and a brief description, indicating data such as the resolution.

The textures have several maps each and are in PNG format.

You can use these textures to apply to your 3D models in Unity and build prototypes quickly. I hope you find them useful.

Brick floor

Resolution: 1024 x 1024 – Maps: 3 – Format: PNG

Introduction

In this article there are 3D models of kitchen elements to download and use in your projects at Unity.

For each model there are representative images rendered in Blender 2.8 and a brief description of the model, indicating topology data and materials.

The models are in .fbx format and can be imported directly into the Unity engine.

You can use these models to build prototypes quickly. I hope you find them useful.

Pot

Vertices: 146 – Faces: 144

Gas Range

Vertices: 663 – Faces:  527

Exit mobile version
Secured By miniOrange