当我调用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);
}}