Skip to content

Alexey Anufriev Posts

Unity Transform* methods explained. Part I - TransformDirection.

Reading Time: 8 minutes

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.

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 .


Can C# struct be assigned to null?

Reading Time: 3 minutes

Types in C# are divided into two groups:

  • reference types (classes);
  • value types (primitives, structs).

The variables of the first group contain the references to the object instances. That is why these variables can be null, means pointing to nothing, or not initialized. But as for the latter group, the variables of it are stored directly as values without references. In this case, null cannot be assigned.

At the same time, C# allows to wrap value types into Nullable struct to make them “optional” and capable for later initialization.

This can be done in the following way:

Nullable<int> value = null;

besides, there is a short notation for the same part of code:

int? value = null;

Nice. But wait a second, Nullable is a struct and structs are value types. How come that it can be assigned to null?

Leave a Comment

GrabPass Blending

Reading Time: 6 minutes

The color palette is very important for games. It allows to percept the action on a screen more naturally. But it also brings additional complications during development. For example, due to similar tint, the background can mask foreground elements.

This problem can be solved by the designer having those elements properly painted (not just a solid color but also adding some gradients, etc.). But this solution can be applied to the elements that are static. Whenever the background shifts the result becomes broken.

At this moment the most suitable solution would be blending of colors controlled in time. In Unity Game Engine this can be done via shader.

Leave a Comment