Quaternion.Inverse on horizontal axis?

I am trying to use Quaternion.Inverse to correct the rotation of a bullet when it bounces off a wall in a 2d game. I’m finding that Quaternion.Inverse only gives the correct angle when bouncing off a vertical wall. How can I make this work for when a bullet bounces off a horizontal wall?

what's a vertical and what's a horizontal wall?

–

1 Answer

1

Quaternion reflection is generally not important to calculate.

Wait, that sounds weird. Why would it be unimportant?

A quaternion doesn’t describe a direction. It describes a rotation relative to an arbitrary starting state/rotation. By extension, an inverted Quaternion describes the opposite rotation away from that initial state/orientation. Fundamentally, it does resemble a reflection, but the challenge lies in describing a proper frame of reference.

Consider a reflection in a mirror: You’re not rotating the object to fit the reflection; you’re reversing it entirely. For every point you see (pixels, vectors, etc.) they’re being mirrored, so the only directly relevant point is the vector itself.

With all of this in mind, a reflected Vector3 will give you the forward direction you’re looking for. Once you have that, you can rotate the GameObject to fit the direction of motion instead.