Close to Floor Location Mini Tutorial
The intention of those mini tutorials is to have simply searchable reference for implementations of among the newer (or altered) options in Niagara.
Right here’s a cool factor you are able to do with collisions in Niagara. It’s barely costlier then beforehand mentioned methods, nevertheless it opens the door to some actually cool potentialities.
We can be utilizing Niagara’s collision hint logic on the CPU to search out floor positions close to our particle system. We will then use this info to exclude particles from spawning, and setting their preliminary place.
Like final time, there’s two methods to comply with the tutorial, both you make it your self utilizing the descriptions and pictures, otherwise you copy over the contents of this pastebin to a brand new module script, after which simply use my steps as an evidence of the inside workings
Here’s a pastebin to the uncooked code of the module, you’ll be able to previous this within your module editor and it’ll convert it to nodes.
don’t neglect to plug into the Output node after copying.
Additionally in case you aren’t going to comply with the remainder of the tutorial, this can solely work on CPU on this kind.
Step 1.
Make a brand new module script and name it one thing cool.
Step 2.
- Open up the module.
- Add a brand new float enter for MaxRadius
- Additionally usher in Engine.Proprietor.Place, that is the world place of your particle impact.
- Add a Random Level in Sphere node, this operate will generate a random direcion.
It comes with the engine and is utilized in Sphere Location, so it’s thouroughly examined - We’re going to wish to normalize this simply in case.
(I set the values to 1 so this shouldn’t be nececary, however the normalize doesn’t price a lot, and never having the vector be normalized will severely mess with the code) - Subsequent, Multiply this route with MaxRadius and add Engine.Proprietor.Place. This can be our worldspace endpoint.
- You would drag this worth straight into the following Step, however I like so as to add it to an area for readability
Step 3.
- Pull out a brand new map get node and add a Collision Question Parameter to it.
- Additionally add Engine.Proprietor.Place once more, and Pull out the native Hint Finish.
It’s attainable that including the Engine.Proprietor.Place node twice has a small perfornance price, I’m pulling it out right here to make our spagetti barely extra readable. - Name the “Carry out Collision Question Sync CPU node”, that is the large one. We would like our particle system place in Begin, and Our calculated finish Place in Finish Hint.
- This operate will Raycast between Begin and Finish and provides us some outcomes.
- We would like our collision to be legitimate if the hint returned legitimate and isn’t inside a mesh.
- For now we simply save the values we’re all for to the map. The brand new legitimate bool, the collision place and the collision regular. For this tutorial, you’ll not want the traditional, however it’s usefull nonetheless.
Step 4.
- If you’d like essentially the most barebones implementation, you’ll be able to skip this step, Simply join Collision world Place to Particles.Place and this can work; Nonetheless it by no means hurts to have some choices when creating.
- Pull out the native collision legitimate bool in addition to the place and regular from the final step.
- Additionally add a set intrinsic bool enter and the Particles.Place
- To ensure we’ve an affordable in case of an invalid collision, use an if node to set the place to TraceEnd.
- I’m additionally including this seperate set intrinsic verify in case I wish to calculate all of the values and have one thing to learn from, however don’t wish to change the place of my particles once I name this module.
Step 5.
- Add a KillInvalid bool enter.
- In case KillInvalid is about, and The collision is certainly not legitimate, we will set DATAINSTANCE.Alive to false. That approach particles that would not have a floor to spawn from won’t spawn.
And that’s it.
Further
It’s helpful to show this module to the library below Location
The highlights will show you how to establish the kind of module within the emitter stack.
And the outline is helpful on your teammates, or your self in a couple of months
Please let me know if you happen to don’t perceive one thing, or if I made a mistake someplace.
29 Likes
Wonderful clarification, I really like these, they’re tremendous useful!
Query: Within the above gif, that simply appears like some particles with trails being spawned in a spherical location with some extent attractor, What’s the floor location module doing there? Might you possibly briefly spotlight a usecase or 2 the place it could be efficient? Thanks a lot once more!
1 Like
I need to admit in hindsight that the gif I posted doesn’t exhibit this tremendous nicely.
The particles don’t spawn in a sphere, they spawn solely from close by geometry.
Probably the most fundamental usecase is any state of affairs the place particles spawning in mid air feels bizarre. For instance you may want your grass ambient impact to spawn the grass from the bottom so it doesn’t really feel like it’s popping out of nowhere.
It may be utilized in electrical results the place you need your electrical energy to arc between bodily surfaces as an alternative of stopping at arbitrary factors. I’m hoping to make a greater instance for this makes use of case at a later level
3 Likes
Right here’s a barely higher look. On this case the one surfaces inside the given radius are from these poles, so the particles spawn from the floor of the pole.
3 Likes
Tesla coils right here we come!
Ahhh ha! Okay, that makes much more sense, I perceive a lot better now, thanks! So if the emitter have been connected to a participant, would it not choose up the close by surfaces and emit particles from them? Wouldn’t it work dynamically like that? I ought to check that out.
1 Like
Hie,
The best way you clarify is very nice.
I simply began studying Niagara, needed to make an impact of sparkler.
Are you able to please information me, like how you can create sparklers impact in it.
Thanks.
2 Likes
Hello,
Thanks for sharing ur information with us
I obtained an issue tho, i cant discover the Carry out Collision Question Sync CPU node.
I attempted to search out it with model 4.25.3 and 4.26.
Can u please assist me, would imply alot to me.
1 Like
Hey, strive pulling out a line from the CollisionQueryInterface to an empty spot and let go to get a operate choice field like within the image.
In the event you open Collision Question, it’s best to see the entire accessible choices
Thanks alot for the quick reply!
I now obtained it.
Whereas i used to be ready for a solution, i spend a while discovering a approach round that node and i discovered this work round. It appears to work, however since i’m only a newbie i dont know if it’s a good resolution, can u inform me ur ideas about it?
Distance discipline collisions solely work on gpu, they’re cheaper, however much less correct, additionally you have to have international distance fields enabled which will increase the reminiscence footprint of your undertaking.
Apart from that they’re just about equal.
One factor you are able to do is make a sim goal change which selects outcomes from both this node or the cpu one relying on if you’re utilizing cpu or gpu-compute sim targets.
This tutorial appears nice and I believe it might resolve a difficulty I’m making an attempt to determine proper now (ie, connecting lightning beams from my character to the bottom or partitions, and many others) however I don’t perceive the ultimate half. KillInvalid is only a bool we created, right? I don’t see what it’s really doing, or the place it’s being set. Additionally, it looks as if “If” nodes don’t exist anymore, so I basically can’t end the final a part of this. Additionally, and I notice this can be a noob query, however how will we really use this module after creating it?