I’m using a ParticleSystem to make a gun shoot a bullet at a target object.
I need to instantiate the ParticleSystem prefab at the position of the gun and pointed at the target object so that the bullet particle flies along the path from one to the other.
I have the position of the source (the gun) and the destination (the target) as Vector3s, and to call Instantiate I need a position Vector3 and a rotation Quaternion.
I’ve googled and searched Unity answers this quite a bit, and as I understand it I should be getting the direction from the source to the destination positions and then use Quaternion.LookRotation to turn that into a rotation:
Vector3 source = GetSourcePosition();
Vector3 dest = GetDestPosition();
Quaternion rotation = Quaternion.LookRotation((dest - source).normalized);
Instantiate(bulletEmitterPrefab, source, rotation);
Unfortunately no matter what I do I can’t get it to work - the ParticleSystem always just shoots straight up.