Notifications
Clear all

[Closed] Look at rotations

Hello, I´m trying to achieve a script that makes an object look at another, for example have obj1 look at obj2. (asuming both objects are at ground level or z position 0)

I´ve tryed asigning a normalized vector ( obj2-obj1) as the z rotation for obj1, but nothing apears to happen.

here is the script I´m using:

obj1 = $teapot01
obj2 = $box01
vector1 = normalize obj2.pos – obj1.pos
obj1.transform.row3 = vector1

Can somebody help me solve this?

Thanks in advance.

David.

7 Replies

you cannot directly assign rows in a matrix – you must build a full maxtix3 value from separate components and then assign it to the transform-
the way you have it – even if it did work the matrix will be skewed and will be of little use to you – you must othagonalize the maxtrix so its axis’s are at 90 degrees – unless of course you want skewing (which i assue you dont)

have a look at the arbaxis command – it is a simple look at –
it can also be done with maxrix3

Thank you for the insight Mark I´ll check the arbaxis method and let you know how I did!

David.

I think I got it! I used a “rotateXmatrix” function and multiplied a direction vector to update de “dir” property of the object I wanted to look at the other object. The only proble is that the “dir” property uses the Z axis diretion so I only need to rotate the back 90 degres in the X axis. That shouldn´t be so hard =)

Here is the code I used:

obj1 = $teapot01 – this is the object I want to rotate
obj2 = $point01 – this is the “look at object”
dirVector = normalize (obj2.pos – obj1.pos)
rm = rotateXmatrix 0
rot = dirVector * rm
obj1.dir = rot

regards.

David.

Hi David,

A great tutorial about how to construct a matrix that points along a certain direction can be found in the reference: How do I align the UVW_Modifier’s Gizmo to a selected face?

It shows how to construct a matrix from a vector, so once you create the matrix you can assign it to your object’s .transform property. I’ve also written a short article on matrices and other things on my site if you’re interested. Hasta la huego,
[font=‘Verdana’][/font]

If you are looking at simple alignments for objects facing eachother the

obj.dir

command can be useful. Simply assign it the value of the normal vector between the two objects.

I.e if you want obj1 to face obj2 then you can use

obj.dir = normalize (obj2.pos – obj1.pos)

This will align the obj1’s z axis and point it towards obj2. Since it aligns the axis sometimes a little pivot manipulation is needed first, but it can be useful for certain scenarios.

Sorry if any of this is wrong. I dont have a copy of 3dsmax on this computer.

Good luck!

Everzen

Thanks for the advise, I´ll look into the reference u sugest James.

David.

True EverZen, that´s how I managed to solve the problem, with the .dir property, thanks.

David.