Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/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# 向某一点发送刚体2d_C#_Unity3d_Game Physics_Rigid Bodies - Fatal编程技术网

C# 向某一点发送刚体2d

C# 向某一点发送刚体2d,c#,unity3d,game-physics,rigid-bodies,C#,Unity3d,Game Physics,Rigid Bodies,我在屏幕外生成一个对象,我想把它发送到中间。抽绳告诉我目标的方向是正确的。但物体会朝任意方向移动。我的计算有什么问题 // add force towards center of screen var targetPosition = new Vector3(Random.Range(-3, 3), Random.Range(-3, 3),00); var forceAmount = 10f; rb2d.AddForce((bigasteroid.transform.po

我在屏幕外生成一个对象,我想把它发送到中间。抽绳告诉我目标的方向是正确的。但物体会朝任意方向移动。我的计算有什么问题

// add force towards center of screen
    var targetPosition = new Vector3(Random.Range(-3, 3), Random.Range(-3, 3),00);
    var forceAmount = 10f;
    rb2d.AddForce((bigasteroid.transform.position - targetPosition).normalized * forceAmount);
    Debug.DrawLine(targetPosition, bigasteroid.transform.position,Color.red,3f);

看来你是在向相反的方向前进。试试这个:

rb2d.AddForce((targetPosition - bigasteroid.transform.position).normalized * forceAmount);

你能再加一些代码吗?此代码是否在update()范围内?