AddForce 方法不起作用

AddForce Method Not Working

我正在为 class 编写一个自上而下的砍杀游戏。我们想要一个机制,如果你被敌人击中,或者敌人击中你,你会得到 'knocked back'。不幸的是,无论我尝试了什么,我都无法让敌人或玩家对力做出反应。

以下是我检查过的其他问题中建议的事项列表,例如:

我 运行 没主意了。非常感谢您提供的所有支持。

以下是来自播放器对象的脚本的代码片段:

 public void OnTriggerEnter(Collider col)
{
    if (col.gameObject.tag == "EnemyHit" && !invincible)
    {
        Debug.Log("The player has been hit!");

        //sets player as invincible
        invincible = true;

        // Set the damaged flag so the screen will flash.
        hit = true;

        timeOfHit = Time.time;

        // Reduce the current health by the damage amount.
        currentHealth -= 1;

        GetComponent<Rigidbody>().AddForce(transform.forward * recoilThrust, ForceMode.Force);
        Debug.Log("This is the force that is being added to the player when it is hit. : " + -transform.forward * recoilThrust);
         //...
         }
 }

我可以证明(使用Debug.Log)函数,代码到达那里,并计算力。

是否启用了运动学?这样做会使物体忽略物理力。

总结评论:

Rigidbody.AddForce 当对象除了刚体之外还有 CharacterController 时不起作用。在这种情况下,效果必须是 "faked"。可以在这里找到可能的方法:

基本上你需要使用CharacterController.Move施加力。