[Solved] Move on local axis

How can i translate an object on its local axis in Haxe? Simular to ‘translate on local axis’-node.

Coordinates in the object.transform.loc variable actually are in local space. If you want to move the object forward along the local Z axis then you just…

object.transform.loc.z += 1;

The call to buildMatrix() is required to apply any changes that you make to the rot, loc, scale of the transform. If you ever change those properties, you have to call buildMatrix() to apply the changes.

but when i do this in my script, the objekt still moves out of the frame as it would do with be transformed in wolrd space.

var dt = Time.delta;
object.transform.loc.x += 5*dt;
object.transform.rotate(new Vec4(0,0,1), 2*dt);

There is a button in the node editors “T”-panel that brings you right to the selected node’s Haxe code. (https://github.com/armory3d/armory/blob/master/Sources/armory/logicnode/TranslateOnLocalAxisNode.hx)
The nodes code generally works in usual Haxe as well.
For this node the world direction(object.transform.world.look()/up()/right(); ) is being multiplied with the speed the object should move at, and this Vector is then put into object.transform.loc.add(vec); roughly speaking.


Oh, my bad. I forgot: the location is in local space relative to it’s parent. So changing its loc on X will move it along the X relative to it’s parent, not relative to itself.

@Simonrazer’s got it right.

1 Like

Thanks a lot guys, Open Node Source is a verry cool feature!

Maybe this will help someone else, so here’s what i made out of the node’s source:

package arm;

import iron.system.Time;
import iron.object.Object;
import iron.math.Vec4;

class Cubecontroller extends iron.Trait {
	var loc = new Vec4();
	var vec = new Vec4();
	var speed = 5.0;
	var rotspeed = 1.0;
	public function new() {

		// notifyOnInit(function() {
		// });

		notifyOnUpdate(function() {
			var dt = Time.delta;
			// speed = speed * dt;
			// object.transform.loc.x += 5*dt;
			object.transform.rotate(new Vec4(0,0,1), rotspeed*dt);


			vec.x = loc.x * speed *dt;
			vec.y = loc.y * speed *dt;
			vec.z = loc.z * speed *dt;

		// notifyOnRemove(function() {
		// });