- Home /
Creating an octopus / squid that spits ink with a particle system?
I am a newbie in unity and have not much experience in scripting. I have modeled an octopus using maya, and imported into unity. I wanted to have the octopus to spit ink when the first person controller approach it. I planned to do it with the triggered animation and a particle system. Is that a good way to do it? How can create the physics of the liquid ink projected out powerfully?
Answer by Willium_Bob_Cole · Mar 21, 2013 at 11:52 PM
Use GameObject > Create Other > Particle System to create your own. There are a ton of options and things to play around with though, and if it seems daunting, import the standard asset folder "Particles" and use some pre built ones, play with the settings on those to get different effects. You will notice they will often have different layers, so one layer could be big, slow moving white particles for smoke, with lots of small, faster moving particles in the middle for the fire. When I first used Unity particle systems, I took a standard fire particle system, and tweaked it until I got a nice, cartoon style, almost volumetric flame, blue in colour, that acted as the head of a character my friend was making. I had to make the speed and death rate quite high to keep the particles as close together as possible so the head didn't become a long blue trail as the character walked around.
Basically, just play with it, particles can be fun! Just be sure to only use them when necessary, I have seen people instantiate one particle system after another, for rocket launchers etc, and if they are not properly killed, they will cause all sorts of problems, as they could be taking up valuable memory and processing power when you don't need them any more.
Thanks a lot man! I played with particle system and managed to create something close to spiting ink. Then I wanted it to have a triggered zone. So the octopus will only spit ink when the player is close to it. I found the script and learned that I need a mesh emitter, particle renderer and particle animator. The $$anonymous$$esh emitter's properties are very different from the particle system. I played with the emitter for 2 days, and still could not figure out how to create the ink / smoke effect. The particles are just appearing at blocks of dots. The trigger zone is also not working. What values should I put in for the particle emitter? Any suggestion?
Thanks a lot man! I played with particle system and managed to create something close to spiting ink. Then I wanted it to have a triggered zone. So the octopus will only spit ink when the player is close to it. I found the script and learned that I need a mesh emitter, particle renderer and particle animator. The $$anonymous$$esh emitter's properties are very different from the particle system. I played with the emitter for 2 days, and still could not figure out how to create the ink / smoke effect. The particles are just appearing at blocks of dots. The trigger zone is also not working. Any suggestion?
If your particle system looks right, then you don't need to add anything else such as mesh emitter etc, all those things should be included as long as it looks right in the editor.
The way I do trigger volumes is to create a box, and tick 'is trigger' in it's inspector properties, then make a trigger material that can be whatever colour you want but make it semi transparent, that way you can still see, move, and resize it in the editor, without covering up the rest of your level. Next, make a triginvis script that you apply to any trigger you make so it isn't visible when you play the game. If you are using javascript, it will be:
function Start()
{
renderer.enabled = false;
}
Simples. You can also prefab this so you can use as many triggers as you need quickly and easily. Then, for each trigger that you need to actually do something, make a new script, using function OnTriggerEnter() and tell it what to do. So to enable your particle emitter, use:
var SquidInk : ParticleSystem;
function OnTriggerEnter()
{
Emit();
}
function Emit()
{
SquidInk.Play();
yield WaitForSeconds(3);
}
Just be sure that your particle system is not set to loop and this should be good to go. to assign your particle system to the variable SquidInk, you need to either drag it from you assets browser into the SquidInk slot on the trigger's inspector window, where your script will now be, or, you can click the little dot next to this variable in the inspector, and assign it through the pop up.
Hope this helps, it should work fine but if it gives any errors let me know!
Thanks Willium_Bob_Cole!
So I created a capsule collider for that ink prefab that I have and dragged it to the scene. I also added in your script and dragged the ink prefab as its required particle system. However, I got an error saying :
nullreferenceException: Object reference net set to an instance of an object. UnityEngine.ParticleSystem.Play (Boolean withChildren)