- Unity Relative Direction
- Unity Random Direction
- Unity Direction Facing
- Unity Directional Audio
- Unity Get Direction
In general, game engines deal a lot with geometry. Everything like point, vector, line or 3D model can be represented as a set of Coordinates. Each Coordinate must be related to some Coordinate Grid.
This is the first video of 'hope-to-be' quickie series(very short and quick unity tutorials because your time is precious) about changing direction of gravit. Change rotation unity with vector. Rotate towrards the move direction 2d. Unity vector with rotation. Unity rotate towards point 2d. Unity rotate towards vector3. How to rotate unity 2d. Unity rotation object. Unity of Direction states that a particular team of employees with the same goals as well as the same objectives need to work together to achieve those common goals for the success of the company. It has facilitated several organizations in achieving the objectives of firms that they want to have in the industry.
Usual Coordinate Grid is represented by its origin (starting point) and a set of axis.
Unity supports two types of Coordinate Grids (also called Spaces):
- World – single for the whole scene with the fixed origin bound to the scene center.
- Local – one per each object within the scene but with the origin bound to the object pivot.
Very often it is required to transform a coordinate from one space to another. To do this operation Unity provides a set of methods:
- TransformDirection
- TransformPoint
- TransformVector
- InverseTransformDirection
- InverseTransformPoint
- InverseTransformVector
The first 3 methods do a transformation from the local space to the world space and the last 3 do the opposite operation. The reason why there is not only one method but a set is following: different types of transformation can be dependent on different factors like rotation, position or scale of the coordinate’s owner (the owner of the local space). The documentation for each method is quite short but the transformations behind are not so trivial.
The goal of this set of articles is a detailed explanation with illustrations of each transformation. This should give a clear understanding of each method and allow to do a wise choice during development.

For better comprehension, the explanation of all three transformation types is divided into parts: one for each type. Current post is about TransformDirection method 1 .

The understanding of ‘Direction’ definition will help to understand the related transformation.
Direction – a line that connects defined start and end points. For example, if an object goes along the line that connects points A and B then this object is following direction. If the direction is represented by one coordinate that means that the starting point is (0, 0, 0).
In Unity, the direction is mostly represented by one coordinate, thus the starting point is always in the center of the coordinate grid. But since there can be two centers: world and local, it is a purpose of transformation functions to find a point that will represent the same direction but within another space. This sentence briefly explains the logic of the transformation behind. Below there is a detailed and illustrated explanation of the transformation step-by-step.

Local Coordinate
First, let’s start with a local space. For example, there is an object (that represents an origin of the space) and a point (0, 0, 1) located in the same space.
Here and below the direction will be represented by the orange arrow
World Coordinate
Now this object together with the local point (A) can be placed somewhere in the world space. There, this point A has a coordinate (2, 3, 1). But since the related object was only moved from the world origin it is very easy to find a point A’ in world space that will represent the same direction. To do this the object’s origin (or the object itself) has to be aligned with world origin (simply moved to the world space center) and this will give a coordinate (0, 0, 1).
As long as the object with the related local point is only moved in the world space the direction coordinate will be the same for both spaces. Here is one additional requirement that must be satisfied to make the transformation so easy: the rotation of both spaces must be equal.
Rotation
Before
Let’s try to rotate the local space (or simply the object itself) by 90 degrees along the X-axis:
Unity Relative Direction
Currently, the local Z-axis is looking at the viewer but after the rotation it will look down.
In the world space this rotation will look like this:
After
Now the rotation is done and the situation is following:
- X-axis was untouched since the rotation was done along it;
- Y-axis is now looking at the viewer, but not at the top as it was before;
- Z-axis is now looking at the bottom;
- The coordinate of the Point A was unchanged since it was bound to the axis.
So world rotation does not affect local points. But in the world space the coordinate was changed, and now it is (2, 2, 0). To find the direction in the world space the same operation must be performed: the object must be moved to the world space origin. And as it is visible on the picture, the direction is different from the previous example, it is (0, -1, 0).
Now the logic of TransformDirection is clear: align the local space with the world space and see where the local point appears in the world space.
Math Behind
How to align the local space with the world space?
This operation* is done in a few steps:
- The local space origin is moved to the world space origin;
- Each point from the local space is moved in the same direction by the same distance as the local origin.
* This operation must be done in world coordinates.
From the last example there are following inputs:
- Object coordinate (local space origin): (2, 3, 0);
- World space origin: (0, 0, 0);
- Point A coordinate: (2, 2, 0).
To move the object from source coordinate (2, 3, 0) to the target coordinate (0, 0, 0) its coordinate has to be substructed as follows:
(2, 3, 0) – = (0, 0, 0)
= (2, 3, 0).
Unity Random Direction
The substraction here is done per coordinate component: )
And now the A point can be moved as it is described in step 2 (in the same direction by the same distance so using ):
Unity Direction Facing
(2, 2, 0) – = (2, 2, 0) – (2, 3, 0) = (0, -1, 0)
Consequently the formula behind TransformDirection is following
Links
1.https://docs.unity3d.com/ScriptReference/Transform.TransformDirection.html
16,914 total views, 4 views today
The traffic and directions example is a visualization of Mapbox's traffic data and Directions API.
Traffic
In this example scene, traffic is visualized by leveraging the Mapbox Traffic v1 tileset, which provides constantly updating congestion information. The tileset is specified in the Map Layers settings as a Custom
Data Source as shown in the screenshot below. You can specify multiple tilesets as data sources by separating them with a comma. For more information refer to the documentation on using custom data in Unity.
Map Features are used to render the congestion data inside of Unity. Navigate to Map Layers > Features > Map Features
to see how the visualizers are configured. The Mapbox Traffic v1 tileset gives access to layers and fields that are used for this visualization. The traffic
layer of the tileset contains the congestion
key which has low
, moderate
, heavy
, and severe
as possible values. Each one of these keys are configured with a separate visualizer so that it can be styled and rendered appropriately. To see how the vector features interact with tileset data, inspect the LowTrafficCongestion feature.
Select LowTrafficCongestion to view the configuration and you'll see the following settings:
Filters
- View the configured filters by navigating to Filters.
- Key is set to
congestion
. - Operator is set to
Contains
. - Str Value is set to
low
.
- Key is set to
Modeling
- Primitive Type is set to
Custom
. - Layer Name is set to
traffic
. - Snap to Terrain is checked and Combine Meshes is unchecked.
Behavior modifiers
Unity Directional Audio
Styling of this feature is handled in Behavior Modifiers by the following modifiers:
- Mesh Modifier: A LoftModifier is specified to achieve a 3D look.
- Game Object Modifier: A MaterialModifier is specified to color the area with low congestion a specific color.
Directions
Mapbox Navigation is available inside of Unity, and is configured using the DirectionsFactor.cs script. In this scene there is a Directions
game object that has the DirectionsFactory script attached to it. Additionally, it has two waypoints as children that are the markers on the map. Every two seconds the DirectionsFactory will query the Directions API and return the driving route between the two points. If the points have moved within that time, a line will be rendered along the new driving route.
The DirectionsFactory script contains the following:
Unity Get Direction
- Map: This field contains the map game object for this scene.
- Mesh Modifiers: This is an array of mesh modifiers. It contains a LoftModifier to place a line on top of the traffic mesh.
- Material: This contains the material to style the line along the directions route.
- Waypoints: This array contains the waypoints of the route.
- Update Frequency: This setting controls how often the Directions API is queried and updates the route if the position of the waypoints have changed.
To configure directions in your own scene, you can drag the Directions prefab into a new scene or attach the DirectionsFactory script to an empty game object.
