Hello, Community!
I would be very grateful if I could answer this question.
I did not speak English and I used Google Translator.
I am developing an App using Hololens and Unity.
Using a gesture to move the object in the direction
Goal.
We have confirmed that the y and z axes are now properly implemented and distributed to Hololens, so that they work normally.
I made a lot of effort, But the x-axis does not know the correct answer.
Here is my code:
Vector3 heading = this.gameObject.transform.position - XVeil.Instance.HeadTransform.position;
var distance = heading.magnitude;
var direction = heading / distance;
if (args.Position.x > 0.8 || args.Position.x < -0.8)
{
// This is Problem
Vector3 dir1 = this.gameObject.transform.position - Vector3.zero;
Vector3 dir2 = this.gameObject.transform.position - XVeil.Instance.HeadTransform.position;
float angle = Vector3.Dot(dir1, dir2);
Vector3 moveVector = args.Position - oldPosition;
Vector3 newPos = Quaternion.Euler(0, angle, 0) * moveVector;
this.gameObject.transform.position += newPos * offset;
oldPosition = args.Position;
}
else if (args.Position.y > 0.8 || args.Position.y < -0.8)
{
// this is OK
Vector3 newPos = args.Position;
newPos.x = 0f;
newPos.z = 0f;
this.gameObject.transform.position += newPos * offset;
}
else if (args.Position.z > 0.8 || args.Position.z < -0.8)
{
// this is OK
this.gameObject.transform.position += direction * args.Position.z * offset;
}