So right now i have a decal system. It adds decals when i shoot something.
I use the impact normal to add the decal in the correct orientation.
What I am missing: I want to randomize the rotation a little bit.
Hard to explain the issue but the impact normal is using the blue arrow (forward) to represent the normal.
The decal is using the green arrow (up) to represent how it projects to the surface.
var rot = Quaternion.LookRotation(direction);
var eulerAngles = rot.eulerAngles;
rot.eulerAngles = new Vector3(eulerAngles.x + 90f, eulerAngles.y, eulerAngles.z);
Then I create a Matrix to add to the decal system.
As you can see I just add 90 degrees to fix the rotation of the decal to make sure it always projects correctly. However I can’t figure out how to add a random rotation while preserving the orientation.
First of all you should not convert the quaternion to euler angles. Euler angles will just give you much more issues in the long run. Especially a 90° rotation around x will perfectly put yourself into the gimbal lock orientation. You should simply orient your quad so its normal is equal to the forward axis. Unity’s default quad mesh (note: quad, not plane) does have this orientation. It simplifies the usage with LookRotation.
To rotate your quad around the normal axis you can simply multiply your quaternion on the left with a random rotation around your normal axis. So you can use Quaternion.AngleAxis for this.
var randomRot = Quaternion.AngleAxis(Random.Range(0,360), direction);
rot = randomRot * rot;
Hi. Thank you for taking the time and replying.
I guess I should have made it more clearer that these are real decals and not meshes, which makes it harder.
However you still helped me understand from what you are saying that the only way is to replace the mesh that the command buffers are using.