Log in or register to post comments

How can I get AR Camera angle?

December 15, 2013 - 5:12am #1

How can I get AR Camera angle or position?

I need that to rotate my character depends on the angle of the AR Camera..

Thx

How can I get AR Camera angle?

November 2, 2014 - 6:40pm #5

I am looking to do something similar. Basically, when the user rotates the image target it changes the x and y of the gameobject relative to the image target. So if I want to move the game object it will move it up in the direction of where y is now pointing due to the user rotating the image target. What I am looking to do is no matter what direction the image target is rotated too I want to keep the direction of up as up, down as down and so on.

I have played around with the Arcamera Z rotation to check it so I can adjust my gameobject direction accordingly. But I find that the value bounces around so much that I can't create logic to check for a 90, 180, 270 or 360 rotation. Is there an easier and more accurate way to do this? It's almost like I have to sample the z rotation data for it to be accurate.

 

thanks!

How can I get AR Camera angle?

December 16, 2013 - 9:29am #4

In a script attached to AR camera:

public Transform targetObj;  //set in inspector

void Update(){

Debug.Log(targetObj.rotation.eulerAngles);

}

 

Will give you the angle of the camera to the target in euler angles or you can do "targetObj.rotation" to get the rotation as a quaternion...

 

If you want your model to turn left/right relative to the target, I usually make an empty gameobject and child it to the target as a "spawn point", in the center, with z axis pointed to what I want forward. Then change the character's rotation relative to that point, then if you want to reset the character's position (say you lose tracking, then find target, and you want the target to start back at the beginning) you can set it to the position and rotation of the empty gameobject (spawn point).

 

So to reset position and rotation if you have the spawn point as a variable:

public Transform spawnpt;
public Transform targetObj;
public Transform character;


public void ResetChar(){
    character.position = spawnpt.position;
    character.rotation = spawnpt.rotation;
}

 

How can I get AR Camera angle?

December 15, 2013 - 9:44pm #3

I'm making 3rd person game.

What I'm trying to accomplish is when I press 'Right Button', my character will face to the right direction from the camera then move forward.

What can I do now is when I press 'Right Button', my character only rotate to the right then when I press when I press 'Up Button', it will move forward depends on where it faces.

 

Thanks..

How can I get AR Camera angle?

December 15, 2013 - 10:58am #2

The camera position and rotation are accessible from the camera's .transformhttp://docs.unity3d.com/Documentation/ScriptReference/Transform.html

But these will be 0,0,0 unless the World Center Mode is set to a target - i.e. for WCM = Camera , the scene origin is the camera position. 

What is it that you're trying to accomplish?

Log in or register to post comments