x


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-

more ▼

asked Jul 09 '10 at 08:17 AM

remvan3d gravatar image

remvan3d
49 8 8 14

(comments are locked)
10|3000 characters needed characters left

1 answer: sort newest

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.

more ▼

answered Jul 09 '10 at 09:33 AM

spinaljack gravatar image

spinaljack
9.1k 18 31 91

This helped me too! But when the player leaves the water, the splash effect continues to appear...

Jan 04 at 07:00 PM smirlianos
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x984
x639
x199
x162

asked: Jul 09 '10 at 08:17 AM

Seen: 3257 times

Last Updated: Jan 04 at 07:00 PM