拍摄时如何增加滑动击退力?

时间:2019-11-12 17:52:34

标签: c# unity3d

当我调用Shoot()函数时,我希望我的角色像在冰上一样被推回去。我设法使用AddForce将字符推回去,但它立即发生。我希望击倒动作逐渐将角色推回原位。

public class Shooting : MonoBehaviour{


public Rigidbody characterKnockback;
public Transform firePoint;
public GameObject bulletPrefab;
public float bulletForce = 20f;

void Update()
{
    if(Input.GetButtonDown("Fire1"))
    {
        Shoot();
        characterKnockback.AddForce(Vector3.back * 25f * bulletForce);
    }
}

void Shoot()
{
    GameObject bullet = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
    Rigidbody rb = bullet.GetComponent<Rigidbody>();
    rb.AddForce(firePoint.up * bulletForce, ForceMode.Impulse);
}}

0 个答案:

没有答案