How would I make the camera always point at an object? (java)

I’m trying to make a scene and I need the camera to pint at the baby at all times, how do I do that?

Hi @Ian_Hendricks,

It does depend a little on what control you want your user to have, ie, can they still move around? do you want them to have no control? etc.

But the basic code is:

let baby = Scene.getItem("zjN5R7Ou") as AnimatedItem;
let cam = Scene.getItem("gdson9Vf") as CameraItem;

Time.scheduleRepeating(()=>{
    cam.transform.lookAt(baby.center);
},0.01);

See this remixable example:

In this example the user can still move around, but can’t look around.

Hope that helps! Let me know if you have any further questions about this. If this solves your problem, please mark this post as the Solution.

Many thanks,
Geoff @ TechLeap

1 Like