# Tag Info

5

The simplest way to do this is to compute a correcting rotation every time the camera moves: axis = cross(newPosition, oldPosition); angle = acos(dot(normalize(oldPosition), normalize(newPosition))); ...and then rotate the camera's orientation matrix/quaternion/basis vectors by this correction. But since the movements are likely to be small and frequent, ...

5

Click on the object in the scene, and look at the Rotation values in the Inspector. This will tell you which way the object is oriented in absolute terms. If the orientation does not match your expected axis (for example, 90 degrees off, or using an unintuitive axis for a given direction), you cannot change the axis of the object itself. Instead, you can ...

5

The sign of the dot-product of C with AB will be positive when the vector component of CD parallel to vector AB is in the direction AB, and negative when it is in the direction BA. The sign of the (z-component of the) cross-product of vector CD with vector AB will indicate which side of AB the agent is approaching from. Depending on your sign conventions, ...

4

Yes, in fact that's what quaternions are often used for - interpolating between two different orientations. Other methods of representing orientation suffer from issues like gimbal lock and wrap-around. Left is quaternions, right is Euler angles https://answers.unity.com/questions/717637/how-do-you-smoothly-transitionlerp-into-a-new-rota.html For accuracy, ...

3

You can just check if the width of the screen is less than the height - if this is the case, then you definitely have a monitor in portrait mode.

2

If I understand what you're asking, the vector CD is just a vector, not a ray, so only the direction matters, not location. However, AB is a line segment, not just a vector, so its location matters. Your tests have one 'if' test to make two cases, but I think you actually have four cases. Let's look at the diagram in AB's reference frame: If you can ...

2

Alright so I figured out an even more ideal solution. The way I was trying to solve the problem was going to lead to more issues than I needed to deal with, so instead I slept on the problem and thought up a different approach. Instead of trying to min-max my orientation, I now calculate how far from the target orientation the camera is, If it lays above a ...

2

I bit on the mathematical side, but here's a Q & A on MSE on computing quanternion distance. Using that you could do something like: quat targetQuat = target->getOrientation(); quat currentQuat = getOrientation(); quat lerpQuat = glm::lerp(currentQuat, targetQuat, 0.05f); quat maximumQuat = targetQuat*quat(0.707, 0, -0.3535, 0); float d1 = ...

2

If I understand correctly, you are making gravity a vector, and that is messing the rest of your code base. So, first of all, as Anonymous Anonymous points out you will have to make velocity a vector. In fact, any other thing will probably have to be a vector too. Note: I will not define what a vector is. Also, everything I say here is for working in 2D. ...

2

Take the vector pointing from the first point to the second and also the vector from the first point to the camera position, take their cross product. This creates a vector perpendicular to the other ones. Take this vector and the one pointing from the first point to the second and take their cross products too and normalize it. This gives you the normal of ...

2

Turn the quaternion into a 3x3 matrix, transpose it (shortcut for the inverse of a purely rotational matrix), apply this matrix to your world space vector and you now have your model space velocity vector (entity's virtual axes: X=right, Y=Up, Z=forward or backward).

2

you can set the velocity to "world space" and just provide a vertical velocity, the particle system will follow the hand orientation, but the particles emitted will always move upwards.

2

This is a major bug in Unity. For those who are stumbling here trying to find a solution, a very awesome gentlemen posted a fix over here at github https://github.com/hvs-clark/unity-android-rotation-lock Hopefully Unity fixes this crazy bug soon, so we don't have to use workarounds like this in the future. From what I read, it is by design, which in my ...

2

I solved the problem with another Quaternion multiplication (rotation). Keep in mind: The Quaternion multiplication order does matter. The Code is the following private Gyroscope phoneGyro; private Quaternion correctionQuaternion; // Start is called before the first frame update void Start() { phoneGyro = Input.gyro; phoneGyro.enabled = true; ...

2

The resting yaw rotation is determined by the magnetometer - it's the only one of the three sensors that has an absolute reference direction in the horizontal plane. Unfortunately, it's also the most fiddly of the sensors. Metal components inside the device can cause its detected magnetic field vector to be shifted (hard iron distortion) or stretched/...

1

You can check the source code for how Unity does it: // The red axis of the transform in world space. public Vector3 right { get { return rotation * Vector3.right; } set { rotation = Quaternion.FromToRotation(Vector3.right, value); } } // The green axis of the transform in world space. public Vector3 up { get { return rotation * Vector3.up; } ...

1

In case anyone comes across this, here is how I solved it (for my needs at least). This solution requires the target object have an parent GameObject (child position offset 0,0,0). Both must be specified as parameters to the script. using System.Collections; using System.Collections.Generic; using UnityEngine; using System.IO.Ports; public class ...

1