[SOLVED] Creating a "look at" node setup

Since armory fails compiling for me at the moment (seems like the Kha API changed…), I cannot validate this setup, but this is what I would’ve done. Although it looks just like what you have described about your setup… Maybe, just maybe, there is an issue when not using the x axis as facing, but I really doubt it. I will look into it, once I can compile again.

As far as I know, all the nodes use radians for rotation. There was one which used quaternions, that’s why I inlcuded that output.

1 Like

@ zaethan
Is it possible to get an object to move in the direction that it is facing? The Translate on Local Axis node doesn’t seem to be working and Translate object only moves in specific set directions.

Front facing axis and Main rotation axis does not have default values :joy:

Setup the axis values , the look at logic node works as expected.

Would it be good to add rotation speed option to the node or make a new node with speed parameter ?
For example some device turning to the player with a constant slow speed, the player can avoid it’s ranged attacks by moving faster.

Yeah, I wasn’t sure about whether I can set default values for vectors in python, so I skipped that. Maybe I should’nt have done that, sorry for wasting your time because of this… But hey, at least it’s working now :grinning:

As for rotation speed, I don’t think this node is the right place for this. Above, you already mentioned that it has many parameters, and adding speed options would make the node even more complex… I think it would be better to use another node to interpolate between the current rotation of the object and the desired rotation (which could be given by the looking at node). This approach would also add the benefit of being independent of the looking at node for speed based rotation.

1 Like

Translate on Local Axis does not work? It would be the first one I would’ve recommended in this case. You could try using the vector from transform node then.
Like so:


This should do it… Just don’t forget to select the object you want to move in the object node (and also don’t forget to add your nodetree as a trait to an object in the scene).

2 Likes

Does it make sense to everybody that the built-in Look At node should output Euler angles as there is no way to work with the Quat that it outputs ( with built-in nodes, anyway ) and because all of the other nodes use Euler rotation? I want to submit a PR to fix that if everybody thinks that it makes sense.

The LookAt node is exactly what I need for something I’m doing, but I can’t use its output at all with the existing nodes. I could install the logic pack, but I don’t think you should need to in this instance.

@Monte_Drebenstedt I propose you to make your own maths to master precisely what you do and that relatively simply.

What you want is to get a vector that point to a place in the World Space.

To get it, use the Matrice 4x4 of your blue box and substract to it it’s own x,y,z. (that is a kind of (Matblue - Matblue.p)… cf kha.math.FastMatrix4

Then multiply with the 3D position where you want to look at.
(that is (Matblue - Matblue.p) * Matgreen.p )

You must visualize things in vectoriel and use matrix and you will see that’s very simple.

1 Like

the above node worked great for me. But thanks for the explanation.

I really don’t know any other node that uses quaternions (aside from the QuatToEuler node in the logic pack), so I guess it makes sense to remove the quat output for now.
(Another idea would be to add quats to all other nodes that deal with rotation (and maybe remove euler vectors) to strictly distinguish between rotation and non-rotation input/outputs).

1 Like

Some code below works for me:

package arm;

import iron.math.Quat;
import iron.object.Object;
import iron.Scene;
import iron.math.Vec4;

class MyTrait extends iron.Trait {

var cam: Object = null;
var lookat = new Vec4(5, 5, 5);
var q = new Quat();

public function new() {
	super();

	notifyOnInit(function() {
		cam = Scene.active.getChild("Camera");
		lookat = Scene.active.getChild("Cube").transform.loc;
	});

	notifyOnUpdate(function() {
		var loc = cam.transform.loc;
		var angleXY = this.getAngleXY(lookat, loc);
		var angleZ = this.getAngleZ(lookat, loc);

		q.fromEuler(0.5*Math.PI+angleZ, 0, angleXY-0.5*Math.PI);
		cam.transform.rot.setFrom(q);

		cam.transform.buildMatrix();
	});

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

private function getAngleXY(lookAt: Vec4, cameraLoc: Vec4) {
	var xd = Math.abs(lookAt.x - cameraLoc.x);
	var zd = Math.abs(lookAt.y- cameraLoc.y);
	var angle = 0.0;

	if (lookAt.x > cameraLoc.x) {
	  if (lookAt.y >= cameraLoc.y) {
		// quadrant 1
		angle = Math.atan2(zd, xd);
	  } else {
		// quadrant 4
		angle = 2 * Math.PI - Math.atan2(zd, xd);
	  }
	} else {
	  if (lookAt.y >= cameraLoc.y) {
		// quadrant 2
		angle = Math.PI - Math.atan2(zd, xd);
	  } else {
		// quadrant 3
		angle = Math.PI + Math.atan2(zd, xd);
	  }
	}
	return angle;
}

private function getAngleZ(lookAt: Vec4, cameraLoc: Vec4) {
	var dif = new Vec4().subvecs(lookAt, cameraLoc);
	var delZ = lookAt.z - cameraLoc.z;
	return Math.atan2(delZ, Math.sqrt(dif.x*dif.x+dif.y*dif.y));
}
}

I’m trying to create the same effect but @zaethan node setup doesn’t work for me. I have a plane in the scene (button 1) and I want it to be facing the camera at all times. The plane is parented to the cube in the center, which is able to be rotated using the mouse (turntable). As you can see in the example attached, when I rotate the cube, the plane rotates with it. How do I make the plane face the camera the entire time?

Logic Node setup:


From position: plane
To position: Camera

If it helps to know the goal, I will be parenting the plane (button 1) to the end of the cylinder coming out of the cube. As I rotate the cube, i want the plane to be stuck to the end of the cylinder while maintaining its rotation and facing the camera at all times.

Thank you for your time.

Perhaps this way will suit you.

25
Result.
45 02
17

I tried both but no luck so far. Cylindrical works well if the plane is stationary. However, as soon as I parent it to the cube it starts rotating with the parent. The scale of the plane becomes distorted also.