How to convert a world space coordinate into an object space coordinate?

I am trying to figure out a way to create a new node that converts a vector to a given object space coordinate.

Screenshot from 2020-10-23 09-50-43

In practice, Translate Object uses the vector i want the Vector Out to return, but i can’t figure out how to get this working.

The functionality of this node is: If you use Set Object Location using the converted coodinates, the location will be applied as the object is parented to the reference object, but it is not.

If someone have an idea of how to achieve this, i would be grateful. Maybe already there is a way to do this in nodes, but i don’t know.

I can’t understand what you mean.
There are Parent and Child objects:

  • if you move Parent, then Child move;
  • if you move Child, then Parent does not move, and Child moves relative to the coordinates of Parent.

Do you want Parent to move when you move Child?

It is very confuse to explain. I need to create a way to do Third peson character control with logic nodes (makes the character moves with WASD relatively to the camera direction).

I can achieve this by creating an input for Relative Object in Translate Object node. The problem is that this way is very limited (because can be used only for Translate Object).

In translate object, if you check the On Local Axis checkbox, the translate method will be applied related to the direction of the object, you just need to select another object (that is the reference object) and set the camera object (or its axis object) in this case, and the character will move relatively to the camera.

I only want to know the math behind this method, to convert a given vector to a object space and apply it where it is needed. I will take a deeper look as soon i can, but maybe someone already know how to achieve this.

How to convert a world space coordinate into an object space coordinate?

If you answer this question, then for this you need

  • Child World Coordinat = Parent + Child (because they are relative to the parent).
    For example objects Parent (10, 15, 20) and Child (-2, 3, 4).
    The coordinates of Child in the world will be (8, 18, 24) because we are adding them.

  • Would you like to set Child by world coordinates?
    Child = Value - Parent
    For example, let’s set Child in world coordinates to point (3, 7, 9). As a result, we get the coordinates of Child (7, -8, -11).

P.S. I may not have fully understood, sorry

Here is an example file:

All directions (look, up, right) are determined by the transformation matrices of the object.

The camera is defined as follows:

    public inline function right(): Vec4 { return new Vec4(transform.local._00, transform.local._01, transform.local._02); }
	public inline function up(): Vec4 { return new Vec4(transform.local._10, transform.local._11, transform.local._12); }
	public inline function look(): Vec4 { return new Vec4(-transform.local._20, -transform.local._21, -transform.local._22); }

The matrices themselves (view, perspective) are calculated in the buildMatrix() function. Study classes CameraObject, Transform in folder [ArmorySDK_path]\iron\Sources\iron\object.

1 Like

Also, have a look at getLocalVecFromWorld() in TransformExtension.hx, maybe that is what you’re looking for?

I think it is what i am looking for, but i am getting Unknown identifier : getLocalVecFromWorld. Did i miss something? (i am using a custom node to test, i don’t know if this change anything)

import iron.math.Mat4;
import iron.math.Vec4;
import iron.math.Quat;
import iron.object.Object;
import iron.object.Transform;

The line is if (object != null) getLocalVecFromWorld(object.transform, vecIn);

Just a question… this script makes almost what i want, but instead of move the object i just want the vector:


Can i achieve this trough the function you send? I think this is some math with the Look, Up and Right vectors but i can’t even approach the result. I have sure that i am doing it in the wrong way.

If you want to use it, you first need to import that class. But instead it makes much more sense to use it as a Static Extension which is an awesome feature of Haxe. At the beginning of your file (usually after the imports) you simply write:

using armory.object.TransformExtension;

and then you can use it directly on transform objects (the first parameter is automatically set from the object it is called on):

// the first parameter is automatically set, you just pass the second one

I’m not entirely sure what you want. If you don’t use the move() function, it won’t move. So just take the parameter.
Or do you want to have a vector that’s vec.y times into the look() direction for example? Then just multiply both together (scalar * vector = vector). look() gives you a new vector object so if you use mult() on it, it won’t change the look direction, only that vector object.

Sorry for the confusion, now i got it working as i wan’t but does not looks clean:

		var vecOut = new Vec4();

		var right =;
		var look =;
		var up =;

		vecOut.x = right.x += look.x += up.x;
		vecOut.y = right.y += look.y += up.y;
		vecOut.z = right.z += look.z += up.z;

		return vecOut;

You can test it here:

My question now is if there is a way to add the look, right and up values in a cleaner way. They only can be added separately?

Edit: Done. just replaced the last lines by vecOut.add(right).add(look).add(up);

Many thanks!