Unity3D:根据对象所面对的方向添加力

Unity3D: Adding force based on direction an object is facing

我正在尝试制作一个类似于 "worms" 的游戏,玩家可以选择物体的位置(玩家可以将物体移动 180 度左右),然后将力添加到物体朝向的方向。我尝试使用 transform.right 和 transform.forward,但是力并没有被驱动到对象指向的地方。我环顾四周,仍然 found/understand 我能做的。这是我用来拍摄物体的代码:

    void shootIt(){
       transform.parent = null;
        isPlaying = true;
        A.isKinematic = false;
        A.AddForce(transform.up*varSpeed*_multiplier);
} //"A" stands for the RigidBody2D component I got by using GetComponent<Rigidbody2D>();

我们一如既往地非常感谢您的帮助。

试试这个:

void shootIt()
{
    Vector2 direction = transform.localPosition.normalized;
    transform.parent = null;
    isPlaying = true;
    A.isKinematic = false;
    A.AddForce(direction*varSpeed*_multiplier);
} 

还可以考虑强迫自己为变量起一个好名字。 A描述的不是很清楚。