遇到Addforce Unity问题

时间:2014-11-20 21:57:53

标签: c# unity3d

每当玩家击中敌人时,触发该功能并且敌人必须遭受击退,但是当发生这种情况时,在击中之后,如果靠近玩家,则敌人将再次遭受击退,即使没有。遭受打击,这不应该发生......

这里是触发器(碰撞)脚本

public void OnTriggerEnter(Collider hit){
    if(hit.gameObject.tag == "npcSamuraiNormal"){
        hit.rigidbody.AddForce(transform.forward * speed, ForceMode.Impulse);
    }
}

这里是敌人的FSMState

private void ChasePlayerState(){

    if(dir.magnitude < 1.5f)
    {
        state = FSMStates.AttackPlayer;
        return;

    } else if(dir.magnitude >= 10){
        state = FSMStates.SelectHouse;
    return;
    } else if(enemyHealth <= 0){
        state = FSMStates.Death;
        return;
    }

    /*if(dir.magnitude > 15){
        state = FSMStates.Waypoint;
        return;
    } else if (dir.magnitude < 5){
        rigidbody.velocity = Vector3.zero;
        state = FSMStates.Shoot;
        return;
    }else if (enemyHealth <= 0){
        state = FSMStates.Death;
        return;
    } */

    transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(dir), rotSpeed * Time.deltaTime);

    transform.eulerAngles = new Vector3 (0, transform.eulerAngles.y, 0);

    rigidbody.MovePosition(transform.position + transform.forward * speed * Time.deltaTime);

    }

提前致谢

0 个答案:

没有答案