- Home /
How to trigger a particle effect?
Hello.
I have just recently started my internship for a small indy developer in Norway, and have been given the task of creating a prototype level for a future project. My experience is visual level design, and close to no scripting what so ever. I'm a major noob with scripting.
I need to figure out how to activate a particle effect with a contact/collision trigger. To be more precise, activate a water splash after hitting the water with the character. Anyone who can give me a hint on how to set up the script? Preferably in C#, but JS could also work since it's only a prototype project.
-Noob intern-
Answer by spinaljack · Jul 09, 2010 at 09:33 AM
what you can do is place a trigger collider on the water (mesh of box) and instantiate a splash prefab (one shot particle emitter) at the point of contact. Also if the water is perfectly level like in a small lake you can set the exact height of the water, otherwise you'll need to use a raycast to fine the surface point e.g.
var splashPrefab : GameObject; var splashPoint : Vector3; var waterHeight : float = 2.0; // the height of the water if it doesn't move
function OnTriggerEnter(other : Collider){
if(other.gameObject.CompareTag("player")){
splashPoint=other.transform.position;
splashPoint.y = waterHeight;
Instantiate(splashPrefab,splashPoint,other.transform.rotation);
}
}
You can also do a 2nd splash which is smaller and use it with OnTriggerStay so it plays while the player stands in the water as well.
This helped me too! But when the player leaves the water, the splash effect continues to appear...
Nice one, but why does the particle effect repeats all the time when I'm out of the water? :\
I was looking for something similar for my project, but not swim$$anonymous$$g just falling into knee deep flooded basement.
It works great after i merge it into my current script thanks man +Rep
Your answer
Follow this Question
Related Questions
How to trigger an effect when an object is under a shadow? 0 Answers
Get all particles within trigger collider? 1 Answer
How to GetComponent from another Gameobject OnTriggerEnter 1 Answer
network effects 1 Answer
Emit Particle upon Death 2 Answers