Log in or register to post comments

3D model orientation relative to device physical angle

March 4, 2016 - 12:15am #1

Will try my best to explain this in hope someone can help.

Lets take a trigger image that is on a wall and when detected a 3D model of a person is placed in view.  In the camera view you can see the trigger image behind the person model and that the models feet are correctly orientated to face the floor, as if standing up.

This is easy enough as if one presumes the trigger image is going to be on a wall in the editor I can place the 3D model in the expected orientation.

But, if the trigger image is taken off the wall and placed on a desk now the 3D model appears to be lying down because as it is set in the editor that is how it would appear.

Is there a way to get the 3D model to change its orientation angle based on the angle of how the device is held?

3D model orientation relative to device physical angle

March 24, 2016 - 5:29am #4

Just updating to say, yes your suggestion worked a treat!

 

I have implemented it like this:

 

void FixedUpdate () {
    
        Debug.Log (Input.acceleration.normalized);

        float x = Input.acceleration.normalized.y * 90;  

        transform.localEulerAngles = new Vector3 (x * -1, transform.rotation.y, transform.rotation.z);
}

3D model orientation relative to device physical angle

March 6, 2016 - 11:29pm #3

Thanks for the advice, I wil give this a go and see what happens ;-) ;-)

3D model orientation relative to device physical angle

March 6, 2016 - 12:08am #2

Many ways to do this. I think the simplest and most likely to not break across different devices and OS versions is something like the following:

- At the moment that the imagetarget is detected...read the float values from Input.acceleration.normalized

- Use those values to determine if the camera is mostly looking at the floor or mostly looking at the wall. I think you could probably get away with just reading the y axis and see if it's absolute value is greater than 0.5 or less than it. 

- Either have 2 different groupings of your objects...use SetActive(true or false) to turn them on or off. Or use one group, but write a new transform.rotation value.

It will be more sexy to use the gyro instead of the accelerometer, but I've found that I get more trouble down the road for using it.

 

Log in or register to post comments