首页 > 解决方案 > 刚体通过 addForce 移动,但对象本身不移动

问题描述

我正在关注这个视频https://www.youtube.com/watch?v=THnivyG0Mvo这是我的拍摄功能

void Shoot()
{
    muzzleFlash.Play();
    shootingSound.Play();
    RaycastHit hit;
    if( Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
    {
        //Debug.Log(hit.transform.name);

        Enemy1 target = hit.transform.GetComponent<Enemy1>();
        if (target != null)
        {
            target.TakeDamage(damage);
        }

        if(hit.rigidbody != null)
        {
            Debug.Log("******************");
            hit.rigidbody.AddForce( - hit.normal * impactForce);
        }


        GameObject impactGo = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal));
        Destroy(impactGo, 0.3f);
    }
}

刚体添加到目标:

在此处输入图像描述

桶组件:

在此处输入图像描述

这个函数在我的 Rifle.cs 脚本中,该脚本被添加到步枪对象中。一切正常。但是,当我击中具有刚体的对象时,它不会移动,但我可以在场景中看到,当我多次击中它时,刚体正在移动。目标的刚体设置为“使用重力”并且未选中“是否为运动学”。我究竟做错了什么 ?

标签: unity3d

解决方案


可能您添加的力太小,因此需要大量镜头才能产生效果,正如@Horothenic 所说,尝试增加impactForce 变量的值。查看刚体、网格渲染器和碰撞器是否附加到场景中的同一对象。您的问题的标题表明您的刚体正在移动,但您的渲染没有改变。


推荐阅读