我正在观看此视频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脚本中,该脚本已添加到步枪对象中。一切正常。但是,当我碰到具有刚体的对象时,它没有移动,但是当我多次击中它时,我在场景中看到刚体正在移动。目标的“刚体”设置为“使用重力”,并且未选中“运动学”。我究竟做错了什么 ?
答案 0 :(得分:0)
您所添加的力可能太小,因此需要很多镜头才能产生效果,如@Horothenic所说,请尝试增加ImpactForce变量的值。查看刚体,网格渲染器和对撞机是否已附加到场景中的同一对象。问题的标题表明刚体正在移动,但渲染不变。
答案 1 :(得分:0)
给力一个ForceMode。由于您想让物体看起来像是射击,因此我建议使用脉冲,并确保力比物体的质量大很多。
if(hit.rigidbody != null)
{
Debug.Log("******************");
hit.rigidbody.AddForce((-hit.normal * impactForce), ForceMode.Impulse);
}
有关更多信息,请参见此页面。 Force Modes in Unity
答案 2 :(得分:0)
尝试完全删除Animator,动画可以选择写入默认值,如果在动画上编辑了机芯,则由于设置默认值而导致行为不当。
答案 3 :(得分:0)
我做了很多Google搜索之后。这回答了我的问题https://forum.unity.com/threads/mesh-renderer-does-not-move-with-parent-rigid-body.204700/。因此,我需要做的是关闭检查器右上方对象的静态(未选中)。