Search Unity

Particle System with Collisions

Discussion in 'Visual Effect Graph' started by JustAnotherRobot, Feb 9, 2021.

  1. JustAnotherRobot

    JustAnotherRobot

    Joined:
    Mar 21, 2019
    Posts:
    4
    Hello everyone,

    I am pretty new to Unity in general and haven't worked with the VFX graph yet. I did a bit of searching on the internet but am still unsure whether the VFX graph could be a suitable tool for what I want to achieve.

    Basically the goal is to receive live data over the network and display it as a point cloud (e.g. from a kinect). The point cloud that is sent can change with time. Alternatively someone recommended me to use a voxelmap instead of a point cloud. I think the problem would be still the same or am I missing something gere?

    The user should be able to interact with this point cloud. An example would be to place a box gameobject in the scene. I would want to detect a collision/overlap detection with the point cloud so that I know for example how many particles lie inside and which ones they are (position in the world) so I can do some further work on this.
    So I would need a particle-wise collision detection, right?

    I found VFX graph in a youtube tutorial. They showed how well the performance is compared to the native other version (sorry I forgot its name) to do a particle system.

    I saw some older posts, that back some time it wasn't possible to detect a collision with the particles or receive at least the position of a single particle of the vfx graph. Here are some examples:
    - https://forum.unity.com/threads/vfx-graph-collision.813231/
    - https://forum.unity.com/threads/particle-position-and-collision.919793/
    Is this still true? Or are there any workarounds?
    If it is impossible, do you have any recommendations how one could solve this?
    Thanks for any help in advance!
     
  2. mba-nhyde

    mba-nhyde

    Joined:
    Jul 24, 2014
    Posts:
    3
    I did something which sounds like it might be similar, although it wasn't a particle system, using an Intel RealSense camera to sense physical interaction with in-scene object colliders. Using each point from the point cloud from the depth information we could sense when a user broke the physical plane of the interaction space. (Our use case was people standing over a pool of water with creatures in it and if they got too close or reached out for the animals they would move away.) This was done locally on a single machine.
    You might look at the RealSense toolkit and see if it could work for your use case. I'd think that if you could position point data in the scene you could verify if it was colliding (or within) an in-scene object.
    Good luck.
     
    JustAnotherRobot likes this.
  3. JustAnotherRobot

    JustAnotherRobot

    Joined:
    Mar 21, 2019
    Posts:
    4
    Thanks for the hint I will definitely search for the Realsense Toolkit and see if it helps me.
    Since posting this question, I haven't really looked into this much. However I am now returning to trying to implement this system as a prototype.

    You mentioned this:
    In what form would you suggest to this?
    I saw that the lower-performance shuriken particle system seems to offer a trigger for collision on single particles so maybe I could use that. Maybe something like this user did here: https://forum.unity.com/threads/shuriken-particle-system-scripting-and-collision.227722/
    Or did you mean I should actually spawn gameobjects for each point position? I think the number of points might me quite high (if I remember correctly, in one example it was 30.000) so I expect the performance to be bad.
    The performance was why I originally thought about using the vfx graph particles (because of the performance) however I haven't found any source stating that you can add some trigger for a collision on a single particle still. I was wondering if I could check manually in a certain interval if the each point given as an array of its coordinates lies within a the bounding box of an object.
     
  4. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Hi @Inkymind ,

    If I understand you correctly, you want a trigger rather than a collision? (i.e. you don't want the particles to just bounce off or get killed when they hit something, you want to flag them in a way which would allow you to add some custom logic to them)

    If so, it depends on what shape the trigger is going to be.
    The most straight-forward case is just checking the distance from a point you specify via an exposed property in blackboard:

    You can expose a Vector3 or a Position, set it via your code, and then check for each particle position how close they are to it, and create some logic based on the outcome.

    There are a few other variations to this, using Distance from a sphere or from a line, based on what you might want.
    For anything else, it should be possible to math it out. Since you mentioned a box specifically, I put together a quick example with a subgraph for detecting if a point is within a box based on this stack overflow post.


    You can grab it here.

    There's also the Sample Signed Distance Field operator which allows you to make custom trigger solutions based on more complex arbitrary shapes. We have also an upcoming tool to bake SDFs within Unity directly based on your meshes/prefabs, so soon (aiming for the 2021.2 release) you'll hopefully be able to generate them quite easily.


    Hope this helps!
     

    Attached Files: