What's a collider doing to my transforms?

I have three main questions related to colliders & object transforms.

I have a missile and a shield. The shield is a simple quad with a rigidbody and boxcollider attached. The missile is an egg with a thruster. It has a rigidbody and collider attached.

In both questions I have the missile moving forward by:
transform.position + transform.forward * speed * time.deltatime

The shield is fixed in space a few units in front of the camera (at the moment).

Q1
When the missile collides with the shield it veers of at an angle, with its forward vector apparently pointing in the direction it is veering. That, i suppose, is what I would expect. What I do not expect is that after travelling, in what appears to be in a straight line, it begins to curve. What causes this curving behavior some time after the collision, and how would I correct that?

Q2
Sometimes the missile passes through the shield. This is not the typical miss that I would expect when an object is moving fast and between T1 and T2 its position moves past the collider. Rather, when travelling perpendicular towards the shield, it impacts the shield, stops, and then after what appear to be a bit of “struggle”, for lack of a better word, it begins to slowly pass through the shield before taking off at its normal speed. Is this normal? If so, what parameters are controlling whether, and how much the time it takes, to pass through the shield?

Q3- Can you recommend some good resources on the behavior of the physics engine and how it affects transforms and the changes that are user applied in scripts?

If you use transform.position to move your rigidbody, you’re effectively teleporting the missile. There is no way of knowing for the physics engine, where it’ll be next, because it’s velocity is zero. When it hits the shield, there are collisions that the engine tries to resolve by adding force and torque. This causes the missile to have velocity and angular velocity, thus rotating the missile. That changes transform.forward and with that, the direction it’s going.

Q1: Don’t use transform.position = … to move the missile. Turn off gravity of the rigidbody, set the position and direction once and then shoot it off by using rb.AddForce(transform.forward * speed, ForceMode.VelocityChange);

Q2: This is your position script fighting with the physics engine. If you use the approach in Q1, this should not happen.

Q3: I would recommend this: Unity Movement Tutorials
Although this is about character controllers, Jasper Flick writes great tutorials that answer more questions than needed for just the task at hand.

1 Like