- Home /
Looking for direction | Insects crawling on floors/walls | Performance, modularity, help me make insects crawl on the floor/walls
Hello.
I am just looking for a direction.
I want to create tiny insects crawling on the floor and/or walls. It would be great if the insects would react to player and avoid or run away from him, but if not, its ok too. Depends on the performance cost.
What would be the most modular and optimized way to make that? Because the game is in production It HAS to be optimized and it has to be made in a way that level designers can place or determine in levels where they want insects and where they don't want them.
Looking forward to see some ideas and/or directions and/or suggestions and/or tips!
Answer by andrew-lukasik · May 24, 2021 at 02:06 PM
I suggest you use particle emitter for this, either Particle System or Visual Effects Graph. Spawn mesh particles on a plane and make them move randomly in local space so designers can resize & rotate this plane. Particle systems comes with plenty of tools to fake this and make it look good, although require some basic fx skills to setup. What's more you can generate an additional textures with position normals or other custom data.
(source files) To implement this as VFX Graph you may want to think about it as two separate subjects:
Script that generates path data
This script can do raycasts, navmesh generation and sampling etc. - whatever you need to generate a valid path.
Here is a most basic example you can start from:
GenerateVisualEffectData.cs
using UnityEngine;
using UnityEngine.VFX;
[ExecuteAlways]
public class GenerateVisualEffectData : MonoBehaviour
{
[SerializeField] VisualEffect _visualEffect = null;
Texture2D _texture;
void OnEnable ()
{
if( _visualEffect==null ) return;
const int pathLength = 128;
const int numPaths = 32;
_texture = new Texture2D( width:pathLength , height:numPaths , TextureFormat.RGBAHalf , 0 , true );
_texture.wrapMode = TextureWrapMode.Clamp;
for( int y=0 ; y<numPaths ; y++ )
for( int x=0 ; x<pathLength ; x++ )
{
Vector4 vec = Random.insideUnitSphere;
_texture.SetPixel( x:x , y:y , new Color{ r=vec.x , g=vec.y , b=vec.z , a=vec.w } );
}
_texture.Apply();
const string k_paths_param = "my point cache";
if( _visualEffect.HasTexture( k_paths_param ) )
_visualEffect.SetTexture( k_paths_param , _texture );
else
Debug.LogWarning($"no \"{k_paths_param}\" texture param",_visualEffect.gameObject);
}
void OnDisable ()
{
if( _texture!=null )
{
if( Application.isPlaying ) Destroy( _texture );
else DestroyImmediate( _texture );
}
}
}
Vfx Graph
Vfx Graph that moves particles along pre-generated paths + all the special effects fx artists would add (mesh shader animation etc)
But is it possible to make a bug crawl from floor to wall using these systems? That's what's bugging me. If you put a particle system on the wall and another on the floors, the bugs will crawl through walls and floors at the edge that floor and walls meet.
I found this: https://www.youtube.com/watch?v=K5s7FM3CAic&ab_channel=PersistantStudios-PopcornFX
It would be awesome if I could replicate that. Not sure about performance or how one would go about this using current Unity particle systems or if it is even possible to achieve this without writing your own particle system or using another plugin. It would be great if some1 could confirm if its possible and how performant it is.
No need to write your own, new VFX Graph
is most powerful and efficient. It gives you programmable particles simulated on GPU. Limiting factor is vfx knowledge here.
Nope. Vfx graph isn't enough. After a lot of research I see now that the problem is too hard, unless level designers would make separate hidden meshes just for bugs to crawl on, so no dynamic solution.
Your answer
![](https://koobas.hobune.stream/wayback/20220613034127im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Huge Overhead with Empty Scene on iOS? 0 Answers
what's the best to animate 50 circles at once? performance wise on mobile 0 Answers
Will Multiple Billboarding Sprites Kill My Game Performance ? 0 Answers
UNet performance limitations 0 Answers
How do I get rid of seams that are showing up with lightmapping? 5 Answers