Start a new topic
Solved

Unity. Lookat camera!

How can I make 3D character always LookAt/facing camera and still keep vertical?

I tried debuf the Wikitude Camera position and rotation but did not work.


Hi,


Can you please add more details about your problem? The Wikitude Camera position and rotation should work just like any other camera GameObject. 

If you want to only animate the character's head based on the camera position, it really depends on how your character is setup.


Best regards,

Alexandru.

Could please show an example how to make the Character face/look at camera on real device when I try to walk around it?


Hi,


To make a GameObject face the camera, you can simply use:

transform.LookAt(Camera.main.transform);

This assumes the GameObject uses the z+ axis as the front (when selecting the object, the blue arrow points out of the front of the object).


You can make it only rotate on the XZ plane by canceling the Y component of the camera position: 

Vector3 cameraPosition = Camera.main.transform.position;
cameraPosition.y = transform.position.y;
transform.LookAt(cameraPosition);


If you need more Unity specific help, you could try searching the Unity Forums or post a question on Unity Answers.


Best regards,

Alexandru


Thanks Alexandru for prompt answer.

I know how to google, searching and trying solutions before posting here. However this does not seem to work with Wikitude Camera and specific with Markerless case. Sorry for providing you less information.

Tobe exactly, the task is:

- Release a pet on the ground (Markerless/SLAM)

- Move around it.

- Touch a button or touch on it then it must rotate from wherever to look at you (real iPhone device)!

Hi, 


It seems to work for me, but maybe I'm misunderstanding your use case.


In the sample project we provide, in the Instant Tracking example, I modified the InstantTrackerController.cs class by adding the following Update method:

 

protected override void Update() {
	base.Update();

	if (Input.GetMouseButtonDown(0)) {
		foreach (var model in _activeModels) {
			var cameraPosition = Camera.main.transform.position;
			cameraPosition.y = model.transform.position.y;
			model.transform.LookAt(cameraPosition);
		}
	}
}

With this change, whenever I tap the screen, the models (instantly) rotate towards the camera, while remaining vertical to the ground.

Hope this helps.


Best regards,

Alexandru

oh yes! The problem is base.Update ()

The CharacterController on the character must be override.

Thanks you much! It works for me now!

Login or Signup to post a comment