- Home /
Is it possible to use a simulation space besides local or global?
Is there any way to use an arbitrary transform as the simulation space for a particle system? I've got a bunch of GameObjects with a highly-mobile camera in their ancestry, and I'd like for the simulation to all take place relative to the camera. Any ideas?
Can't you just use the transform of the camera as the parent? Note you can create a new transform at runtime which you can make a parent of your particle system.
var trans = new GameObject().transform;
The camera is the parent of the other game objects and the particle systems. The problem is that, using a local simulation space, the particles all move with the transform of the camera, but also with any motion of the particle effect's transform. Using the global simulation space does not account for motion of the camera, so it doesn't take much motion at all to just "blow" all the particles off the screen. I want the desired particle effects to all happen in screen space, as if they are part of a HUD.
$$anonymous$$y fantasy is that, ins$$anonymous$$d being limited to
particleEmitter.useWorldSpace = true; // or false
I could do something like
particleEmitter.simulationSpace = Camera.main.transform;
(This is totally made up, so don't go looking for it. It just seems illustrative.)
Answer by Owen-Reynolds · Jun 01, 2013 at 03:07 PM
Use a 2nd immobile "GUI particle" camera, clearFlag=none? Aimed at y= -1000 or somewhere (or set all the layers and ignoreLayers correctly.)
Anything spawning on a GUI element would use screenToWorld on the guiCam (same as normal.) Anything spawning over a world object could use worldToView on MainCam, then ViewToWorld on giuCam. Uggg, but only on spawning.
Anything tracking a world object would have to go into a list and each frame do that math (but I wouldn't think those would be "gui-particles" anyway.)
Yikes. Okay, so is the easiest way to entangle the motion of a GUI object with the offscreen GUI particles to use a script that sets equal their local position? I would just place all of the GUI objects on a separate camera, but many of them depend on global lighting and cubemaps.
Edit: Never$$anonymous$$d. I see what you're saying about worldToView/ViewToWorld now, which works irrespective of nested parentage.
Is there a reason the particles are limited to global/local? Is this worth putting in a feature request?
World and Local-to-Spawner Space are really obvious things to describe and to want. Think of how much trouble it is just describing what you want here. Then. if you're Local to some other transform, you have to add a slot for what it is, then think of what to do if it's destroyed.
And, I think you can always do anything fancy using Get/Set Particles, hand-changing position.