You'll need to keep the velocity, angular velocity, and position every frame, then add some code to OnCollisionEnter in which you tell the two colliders to ignore each other from now on, and also restore the projectile's original velocity, angular velocity and position.
private Collider col;
private Rigidbody rigidBody;
private Vector3 vel;
private Vector3 angularVel;
private Vector3 position;
private void Start() {
col = gameObject.GetComponent<Collider>();
rigidBody = gameObject.GetComponent<Rigidbody>();
}
private void FixedUpdate() {
vel = rigidBody.velocity;
angularVel = rigidBody.angularVelocity;
position = transform.position;
}
private void OnCollisionEnter(Collision collision) {
Physics.IgnoreCollision(col, collision.collider);
rigidBody.velocity = vel;
rigidBody.angularVelocity = angularVel;
transform.position = position;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…