Expression "look at" help

Hi,

I have an action scene with a 3D cylinder. I want the cylinders to rotate so they “look at” the cameras X and Z position but ignore. Basically it means that the cylinders should only rotate on the Y-axis. That way i get to see the top of the cylinder when i raise the camera and the bottom when i lower it.

I tried inserting this into the cylinders rotation.y animation channel:

lookat(LookAtMe.position, Follower.position)

LookAtMe is the target and Follower is the cylinder

Can anyobe help me out here?

Many thanks :slight_smile:

Cheers,
Henrik

Hey @HenrikMark welcome to the club.

By adding a third parameter to your expression you can define the lookat axis:

lookat(LookAtMe.position, Follower.position, (0, 1, 0))

Will make your y-axis align with the lookat vector. Well, if that doesn’t work try the other alternatives: (1,0,0) or (0,0,1)

You can also alt-L and drag an orange line in the schematic from the follower to lookatme axes. You could add an offset axis under your follower and rotate it, so your object is aligned on your preferred axis.

3 Likes

Hi Sinan,

Thank you for your input.
First of i found out that the expression should go into .rotation rather than .rotation.y - that made the lookat work.

Unfortunately it didn’t really do anything different than the Alt+L orange connection.

I want the follower to rotate on its Y-axis only, so that Y always points straight up.

Can i achieve this?

Hi Henrik,

Yes.

The trick is to use the Lookat function but you just want it to rotate on the Y-axis. Since rotation is a vector with three components, you can multiply your expression with (0, 1, 0). This will multiply the x and z rotation values with zero and keep the y rotation value.

If axis1 is the axis of the cylinder, and you use the default camera naming then you enter this expression in the rotation channel for axis1:
lookat (Default.position, axis1.position) * (0, 1, 0)

1 Like

By the way, I would appreciate if you could explain the reason for such a thing. I’m trying to cook up an expression tutorial and could use this as a case.

1 Like

Imagine you had beerbottles placed on a table and you want them to rotate so that the label always points towards the camera but you want the bottom of the bottle to stay on the table. So the bottles should only rotate around the y-axis.