We want to create a hit effect when one thing collides with another thing. Pretty straightforward, so I listen for collisionstart and instantiate my effect. The problem I’m having trouble with is rotating this effect in the desired rotation.

Ideally, I would do something like

var normal = collisionResult.contacts[0].normal;
var eulerAngles = new pc.Quat().LookRotation(normal, pc.Vec3.UP);
hitEffect.setEulerAngles(eulerAngles);

But there is no such function in PlayCanvas and the math for it is hopelessly complex, as in this post. I was wondering if there ‘is’ a Unity LookRotation equivalent and I’m just missing it.

btw it doesn’t matter if the resulting rotation puts the right, up or forward vector in the normals direction, so long as one of them does: I’ll be able to figure it out from there.

Check this, you can pass the normal and the up vector to get a matrix that can be used for that:

var matrix = new pc.Mat4();
var quat = new pc.Quat();
this.setMat4Forward(matrix, raycastResult.normal, pc.Vec3.UP);
quat.setFromMat4(matrix);
var alignAngles = quat.getEulerAngles();