Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使对象面向其前向向量_C#_Matrix_Xna_Rotation_Angle - Fatal编程技术网

C# 如何使对象面向其前向向量

C# 如何使对象面向其前向向量,c#,matrix,xna,rotation,angle,C#,Matrix,Xna,Rotation,Angle,与我最近的类似,只是这次我想将对象移向一个向量,而不是另一个对象 Vector3 line = dalekList[i].direction; float rotationDal = (float)(-Math.Atan2(dalekList[i].position.X, -dalekList[i].position.Z) / (2 * Math.PI)); Matrix dalekTransform = Matrix.CreateScale(GameConstants.DalekScalar

与我最近的类似,只是这次我想将对象移向一个向量,而不是另一个对象

Vector3 line = dalekList[i].direction;
float rotationDal = (float)(-Math.Atan2(dalekList[i].position.X, -dalekList[i].position.Z) / (2 * Math.PI));

Matrix dalekTransform = Matrix.CreateScale(GameConstants.DalekScalar) * Matrix.CreateRotationY(rotationDal) * Matrix.CreateTranslation(dalekList[i].position);

因此,我需要将旋转(
rotationDal
)放入
CreateRotationY
,只是我不确定如何计算该角度。

如果要“观察”的向量是
dalekList[I]。方向
,应该尝试在其上使用
Atan2
,而不是位置。

应该添加预期的向量是它的前向向量“朝向向量”是什么意思?你的意思是你想让你的对象在那个方向上“观察”?是的,所以它不断地更新它的旋转,以“观察”它的朝向如果你的意思是向量是
dalekList[i]。方向
,你试过在它上面使用
Atan2
吗?还没有,出于某种原因,我试过使用position,我现在就试试看