我正在为一个班级编写一个自上而下的砍杀游戏。我们想要一个机制,如果你被敌人击中,或者敌人击中你,你会被“击退”。不幸的是,无论我如何尝试,我都无法让敌人或玩家对力量做出反应。
以下是我检查过的其他问题中建议的事项列表:
- 玩家/敌人不是运动学的
- 尝试开启和关闭重力
- 没有位置/旋转被冻结
- 玩家/敌人附有刚体
- 玩家/敌人附加了对撞机,一个有一个没有检查“isTrigger”功能。
- 尝试了 OnCollisionEnter 和 OnTriggerEnter
- 力值高,质量、阻力和角阻力低
我已经没有想法了。非常感谢您提供的任何和所有支持。
这是来自播放器对象的脚本的代码片段:
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)函数,代码到达那里,并计算了力。